Categories
- A ll Codes (310)
- ACM (222)
- ACM Technique (18)
- ACM-ICPC (57)
- Adhoc/Brute Force (3)
- Algorithm (83)
- Algo Unsolved (3)
- Asymptotic Notation (3)
- Geometry (2)
- Graph (6)
- All Pair Shortest Path (1)
- BFS (1)
- DFS (1)
- Single Source Shortest Path (2)
- Bellman Ford (1)
- Dijkstra (1)
- Topological Sort (1)
- Number Theory (6)
- Euler GCD (1)
- GCD (1)
- LCM (1)
- Prime factorization (1)
- Sieve of Erastosthenes (1)
- Trial Division (1)
- Recursion (3)
- Fibonacci (1)
- Tower of Hanoi (1)
- Searching (3)
- Binary Search (2)
- Linear Search (1)
- Sorting (13)
- Bubble Sort (1)
- Bucket Sort (1)
- Counting Sort (1)
- Heap Sort (1)
- Insertion Sort (1)
- Merge Sort (3)
- Quicksort (2)
- Radix Sort (1)
- Selection Sort (3)
- Tree (6)
- AVL Tree (1)
- B+ Tree (1)
- Binary Search Tree (4)
- Competitive Programming (1)
- Data Structure (7)
- Linked List (1)
- Queue (2)
- Circular Queue (1)
- Stack (1)
- Future Reference (1)
- Problem Solution (101)
- Codeforces (3)
- DevSkill (1)
- HackerEarth (17)
- HackerRank (4)
- Lightoj (2)
- SPOJ (1)
- Unsolved (1)
- URI Online Judge (34)
- UVa (18)
- Programming Contest (2)
- Programming Problem Solving (18)
- Challenge (1)
- CS Courses (165)
- Art of Effective Living (1)
- Artificial Intelligence (13)
- Assembly Language (3)
- Compiler Design (1)
- Computer Architecture (3)
- Data Communication (1)
- Data Mining (23)
- WEKA (2)
- Database (10)
- SQL (8)
- Digital Image Processing (5)
- Embedded Systems (2)
- Arduino (2)
- Games Development (1)
- Graphics (9)
- OpenGL (7)
- Mathematics (26)
- Numerical Method (18)
- Bisection Method (4)
- Numerical Method (18)
- Microprocessor (1)
- OOP (53)
- Operating System (11)
- Bash/Shell Scripting (7)
- CPU Scheduling (1)
- Simulation and Modelling (1)
- Web Engineering (1)
- DevOps (1)
- Experience (3)
- Events (1)
- Food Review (1)
- Travel (1)
- Financial Knowledge (1)
- Fitness (15)
- Body Transformation (2)
- Bodybuilding (7)
- Cycling (2)
- Fat Loss (2)
- Fitness Motivation (5)
- Health (2)
- Mental Health (1)
- My Gym (2)
- My Life Chart (3)
- My Life Style (3)
- Weight loss (1)
- Graphics Design (1)
- Photoshop (1)
- HigherStudy (87)
- EducationUSA (2)
- English Learning (9)
- Pronunciation (3)
- German Learning (29)
- Germany (9)
- Grammar (10)
- GRE (17)
- IELTS (26)
- Handwriting Improvement (1)
- Listening (4)
- Reading (1)
- Speaking (2)
- Writing Task (3)
- TOEFL (2)
- HTML/CSS (1)
- Job (56)
- CSE (2)
- CV/Resume (4)
- Interview (26)
- Fresher/Intern (3)
- Java (14)
- Software Engineering (3)
- Masters of Science (40)
- Advanced Formal Modelling (3)
- Cloud Computing (3)
- Data Mining (14)
- Implementation of Database (1)
- Introductory Data Analysis(IDA) (9)
- Excel (3)
- LaTeX (1)
- Learning from Data LFD (1)
- Machine Learning (3)
- Mathematics (1)
- Pattern Oriented Software Architecture(POS) (2)
- Real Time Computing (1)
- MSSQL (3)
- Stored Procedures (1)
- T-SQL (1)
- Open Source (6)
- Linux (4)
- Ubuntu 15.04 (1)
- Ubuntu 18.04 (1)
- Ubuntu14.04 (1)
- Ubuntu (2)
- Linux (4)
- Philosophy of Life (170)
- Learning (2)
- Life (10)
- Life Motivation (126)
- Business/Money (6)
- Career/Earning (12)
- Depression (3)
- Fearless Motivation (1)
- Life Quotes (2)
- Life Story/Journey (1)
- Passion (1)
- People Skill/Networking (14)
- Stress (2)
- Study Motivation (58)
- Success Hacks (74)
- Healthy Habit (15)
- Never Quit (36)
- Patience (23)
- Social Skills/Communicative Skills (5)
- Time Management (4)
- Life Productivity (11)
- Life Rules (5)
- Life Skills (4)
- Lifefact (4)
- Lifelessons (8)
- Lifestyle (1)
- Love (8)
- Motivation (17)
- Motivational Posts (7)
- Music (5)
- Poems (2)
- Love (1)
- Poetry (1)
- Ramadan (1)
- Romance (4)
- Sadness (2)
- Sarcasm (2)
- Thoughts (2)
- Pore Abar Bujhbo (8)
- Presentation (8)
- Programming (337)
- Language (306)
- C (152)
- Array (24)
- C library function (3)
- C Refresh (106)
- Function (17)
- logic (1)
- Logic Logic (4)
- Logics (1)
- Memory Management (1)
- Pointer (19)
- String (21)
- Structured Programming (1)
- C# (40)
- C++ (35)
- Vector (1)
- Java (46)
- Javascript (12)
- PHP (18)
- Python (18)
- C (152)
- R (1)
- R programming (3)
- Language (306)
- Project (2)
- Project Report (1)
- Research (53)
- BigData (3)
- Data Science (15)
- Machine Learning (23)
- Natural Language Processing(NLP) (5)
- Plagiarism Checker (2)
- Research Papers (5)
- Research Topic (3)
- Statistics (4)
- Sentiment Analysis (3)
- Software Development (84)
- .NET (34)
- Xamarin (1)
- Android (10)
- ASP.NET (10)
- Debate (2)
- Design Patterns Implementations (7)
- Laravel (4)
- Object Notation (4)
- Regex (2)
- Software Development Life Cycle(SDLC) (4)
- Training (9)
- LICT (9)
- unity3d (1)
- Version Control/SVN (4)
- XML (1)
- .NET (34)
- Tech Tips (21)
- Desktop (1)
- Fix (1)
- Laptop (1)
- Laptop(ল্যাপটপ) (1)
- HP (1)
- Techie Talk (15)
- Tech Debate (2)
- VPS (2)
- Uncategorized (66)
- University Life (3)
- 7th semester (1)
- 9th semester (1)
- Web Links (1)
- বাংলা (10)
- অবজেক্ট ওরিয়েন্টেড প্রোগ্রামিং (1)
- রিসার্চ (1)
- সি প্রোগ্রামিং (2)
- হার্ডডিস্ক পার্টিশান (1)
Random Quote
Random Quotes
-
Category Archives: OpenGL
Draw Midpoint Circle Algorithm with Keyboard Function
Midpoint algo reference: http://www.eazynotes.com/notes/computer-graphics/algorithms/mid-point-circle-algorithm.pdf
http://suraj1693.blogspot.com/2013/11/c-program-for-drawing-circle-using.html
https://birunthag.blogspot.com/2014/05/openglc-draw-circle-with-midpoint.html
https://www.opengl.org/discussion_boards/showthread.php/169955-using-glutKeyboardFunc
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
#include <windows.h> #include <GL\glut.h> #include <stdlib.h> #include<iostream> #include<stdio.h> using namespace std; int r,p,flags=0; void myInit (void) { glClearColor(0.0,0.0,0.0,0.0); // sets background color to white // sets a point to be 4x4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 400.0); // the display area in world coordinates. } void midpoint() { r=20; p=1-r; int xk=0; int yk=r; int xc=200; int yc=200; while(xk<=yk) { if(p<0) { xk++; p=p+2*xk+3; } else if(p>0) { xk++; yk=yk-1; p=p+2*xk-2*yk+5; } glVertex2i(xc+xk,yc+yk); glVertex2i(xc-xk,yc+yk); glVertex2i(xc+xk,yc-yk); glVertex2i(xc-xk,yc-yk); glVertex2i(xc+yk,yc+xk); glVertex2i(xc-yk,yc+xk); glVertex2i(xc+yk,yc-xk); glVertex2i(xc-yk,yc-xk); } } void processKey(unsigned char key, int x, int y) { switch(key){ case '1': flags=1; printf("Hello world!"); break; //default: // break; } } void myDisplay(void) { //int nol = rand() % 100; glClear(GL_COLOR_BUFFER_BIT); // clears the screen // setsthe drawing colour glPointSize(4.0); glColor3f(1.0f,0.0f,1.0f) ; glBegin(GL_LINES); glVertex2i(0,200); glVertex2i(500,200); glVertex2i(255,0); glVertex2i(255,500); glEnd(); glBegin(GL_POINTS); //midpoint(); if(flags==1){ midpoint(); } glEnd(); glFlush(); // sends all output to display; } int main (int argc, char **argv) { //scanf("%d,%d,&d,&d",&x,&y,&a,&b); glutInit (&argc, argv); // to initialize the toolkit; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // sets the display mode glutInitWindowSize (640, 480); // sets the window size glutInitWindowPosition (10, 10); // sets the starting position for the window glutCreateWindow ("My first OpenGL program!"); // creates the window and sets the title glutKeyboardFunc(processKey); glutDisplayFunc (myDisplay); myInit(); // additional initializations as necessary glutMainLoop(); // go into a loop until event occurs return 0; } |
Posted in A ll Codes, Geometry, Graphics, Midpoint Circle, OpenGL
Tagged KeyboardFunc, Midpoint Circle Algorithm, OpenGL
Draw Brasenham Line Drawing Algorithms with Random Lines and Colors
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
#include <windows.h> #include <GL\glut.h> #include <stdlib.h> #include<iostream> using namespace std; int x, y, a, b, nol, R, G, B; void myInit (void) { glClearColor(0.0,0.0,0.0,0.0); // sets background color to white // sets a point to be 4x4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 400.0); // the display area in world coordinates. } void brasenham(int x1, int y1, int x2, int y2) { int dx = x2-x1; int dy = y2-y1; int p = (2*dy)-dx; for(int i =0; i < dx; i++) { if(p < 0) { x1++; glVertex2i(x1, y1); p = p+(2*dy); } else if(p>0) { x1++; y1++; glVertex2i(x1, y1); p = p+(2*dy)-(2*dx); } } } void myDisplay(void) { int nol = rand() % 100; glClear(GL_COLOR_BUFFER_BIT); // clears the screen // setsthe drawing colour glPointSize(4.0); for(int i = 0; i<nol; i++){ int x = rand() % 750; int y = rand() % 850; int a = rand() % 950; int b = rand() % 680; int R = rand() % 255; int G = rand() % 255; int B = rand() % 255; glColor3ub(R, G, B) ; glBegin(GL_POINTS); brasenham(x, y, a, b); glEnd(); } glFlush(); // sends all output to display; } int main (int argc, char **argv) { //scanf("%d,%d,&d,&d",&x,&y,&a,&b); glutInit (&argc, argv); // to initialize the toolkit; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // sets the display mode glutInitWindowSize (640, 480); // sets the window size glutInitWindowPosition (10, 10); // sets the starting position for the window glutCreateWindow ("My first OpenGL program!"); // creates the window and sets the title glutDisplayFunc (myDisplay); myInit(); // additional initializations as necessary glutMainLoop(); // go into a loop until event occurs return 0; } |
Posted in A ll Codes, Brasenham Line Drawing, Graphics, OpenGL
Star Drawing with OpenGL
Draw 4 stars in screen with OpenGL
Screenshot:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
#include <windows.h> #include <GL\glut.h> void myInit (void) { glClearColor(0.0,0.0,0.0,0.0); // sets background color to white // sets a point to be 4x4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 400.0); // the display area in world coordinates. } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clears the screen ;// setsthe drawing colour glPointSize(4.0); //Axis glColor3f(1.0f,0.0f,1.0f) ; glBegin(GL_LINES); glVertex2i(255,0); glVertex2i(255,500); glVertex2i(0,200); glVertex2i(500,200); glEnd(); glColor3f(1.0f,0.0f,0.0f); // glColor3f(1.0f,1.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (40,50); glVertex2i (60,50); //left glVertex2i (40,50); glVertex2i (40,80); //top glVertex2i (40,80); glVertex2i (60,80); //right glVertex2i (60,50); glVertex2i (60,80); glEnd(); //BOTTOM TRIANGLE glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (40,50); glVertex2i (60,50); //left glVertex2i (40,50); glVertex2i (50,30); //RIGHT glVertex2i (60,50); glVertex2i (50,30); glEnd(); //RIGHT TRIANGLE glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (60,50); glVertex2i (60,80); glVertex2i (60,50); glVertex2i (70,60); glVertex2i (60,80); glVertex2i (70,60); glEnd(); //left triangle glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); glVertex2i (40,50); glVertex2i (40,80); glVertex2i (40,50); glVertex2i (30,64); glVertex2i (40,80); glVertex2i (30,62); glEnd(); //Top triangle glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); glVertex2i (40,80); glVertex2i (60,80); glVertex2i (40,80); glVertex2i (50,90); glVertex2i (60,80); glVertex2i (50,90); glEnd(); glColor3f(1.0f, 0.0f, 0.0f); glRectf(120,120, 100, 100); glColor3f(1.0f,1.0f,0.0f) ; glBegin(GL_POLYGON); //RIGHT glVertex2i (120,120); glVertex2i (120,100); glVertex2i (120,120); glVertex2i (150,110); glVertex2i (120,100); glVertex2i (150,110); glEnd(); glBegin(GL_LINES); //RIGHT glVertex2i (120,120); glVertex2i (120,100); glVertex2i (120,120); glVertex2i (150,110); glVertex2i (120,100); glVertex2i (150,110); glEnd(); //left glBegin(GL_POLYGON); glVertex2i (100,120); glVertex2i (62,107); glVertex2i (100,100); glVertex2i (62,107); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (100,120); glVertex2i (110,130); glVertex2i(110,130); glVertex2i (120,120); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (100,98); glVertex2i(110,70); glVertex2i (120,98); glVertex2i(110,70); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (350,315); glVertex2i (350,290); glVertex2i(370,290); glVertex2i (370,290); glVertex2i (370,315); glVertex2i (350,315); glVertex2i (370,315); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,315); glVertex2i (362,325); glVertex2i (370,315); glVertex2i (362,325); glEnd(); // glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (370,290); glVertex2i (385,305); glVertex2i (370,315); glVertex2i (385,305); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (320,305); glVertex2i (350,315); glVertex2i (320,305); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (362,270); glVertex2i (370,290); glVertex2i (362,270); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (70,275); glVertex2i (70,290); glVertex2i(70,290); glVertex2i(85,290); glVertex2i(85,290); glVertex2i(85,275); glVertex2i(85,275); glVertex2i(70,275); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,275); glVertex2i(76,220); glVertex2i(85,275); glVertex2i(76,220); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(85,275); glVertex2i(120,280); glVertex2i(85,290); glVertex2i(120,280); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,275); glVertex2i(38,280); glVertex2i(70,290); glVertex2i(38,280); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,290); glVertex2i(76,335); glVertex2i(85,290); glVertex2i(76,335); glEnd(); glFlush(); // sends all output to display; } int main (int argc, char **argv) { glutInit (&argc, argv); // to initialize the toolkit; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // sets the display mode glutInitWindowSize (640, 480); // sets the window size glutInitWindowPosition (10, 10); // sets the starting position for the window glutCreateWindow ("My first OpenGL program!"); // creates the window and sets the title glutDisplayFunc (myDisplay); myInit(); // additional initializations as necessary glutMainLoop(); // go into a loop until event occurs return 0; } |
OpenGL Graphics Code: Build a house with GLUT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
#include <windows.h> #include <GL\glut.h> void myInit (void) { glClearColor(0.0,0.0,0.0,0.0); // sets background color to white // sets a point to be 4x4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 400.0); // the display area in world coordinates. } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clears the screen glColor3f(0.5f,0.5f,0.5f) ;// setsthe drawing colour glPointSize(4.0); glBegin(GL_POLYGON); //bottom glVertex2i (20, 20); glVertex2i (320, 20); //top glVertex2i (20, 200); glVertex2i (320, 200); //left glVertex2i (20, 200); glVertex2i (20, 20); //right glVertex2i (320, 200); glVertex2i (320, 20); //glVertex2i (10, -50); glEnd(); //Left Window glColor3f(1.0f,0.0f,0.0f) ; glPointSize(4.0); glRectf(30,30,100,100); //Right Window glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (200,30); glVertex2i (200, 100); //top glVertex2i (200, 100); glVertex2i (300, 100); //left glVertex2i (300, 100); glVertex2i (300, 30); //right glVertex2i (300, 30); glVertex2i (200, 30); //glVertex2i (10, -50); glEnd(); //door glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); //left glVertex2i (120,30); glVertex2i (120, 100); //top glVertex2i (120, 100); glVertex2i (170, 100); //right glVertex2i (170, 100); glVertex2i (170, 30); //bottom glVertex2i (120, 30); glVertex2i (170, 30); //glVertex2i (10, -50); glEnd(); //Triangle glColor3f(0.0f,1.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (20, 200); glVertex2i (320, 200); //top glVertex2i (200, 310); glVertex2i (320, 200); //left glVertex2i (20, 200); glVertex2i (200, 310); //glVertex2i (10, -50); glEnd(); glFlush(); // sends all output to display; } int main (int argc, char **argv) { glutInit (&argc, argv); // to initialize the toolkit; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // sets the display mode glutInitWindowSize (640, 480); // sets the window size glutInitWindowPosition (10, 10); // sets the starting position for the window glutCreateWindow ("My first OpenGL program!"); // creates the window and sets the title glutDisplayFunc (myDisplay); myInit(); // additional initializations as necessary glutMainLoop(); // go into a loop until event occurs return 0; } |
OpenGL GLUT Tutorials – C Graphics
Lectures:
About OpenGL colors:
http://www.cs.brandeis.edu/~cs155/OpenGL%20Lecture_02.pdf
https://en.wikibooks.org/wiki/OpenGL_Programming/Basics/Color
Setup:
https://openglprojects.com/setting-up-opengl-in-windows-linux-mac/
Tut:
http://www.lighthouse3d.com/tutorials/glut-tutorial/
http://ogldev.atspace.co.uk/www/tutorial03/tutorial03.html
https://www3.ntu.edu.sg/home/ehchua/programming/opengl/CG_Introduction.html
Vid:
https://www.youtube.com/watch?v=xCRzpNd5k3Y
https://openglprojects.com/opengl-project-ideas/
http://vtupro.blogspot.com/2014/10/opengl-mini-project-for-csisit-students.html
Draw a rectangle with OpenGL
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#include<windows.h> #include <GL/gl.h> #include <GL/glut.h> void display(void) { /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); /* draw white polygon (rectangle) with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glColor3f (1.0, 0.25, 1.0); glBegin(GL_POLYGON); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); /* don't wait! * start processing buffered OpenGL routines */ glFlush (); } void init (void) { /* select clearing (background) color */ glClearColor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); } /* * Declare initial window size, position, and display mode * (single buffer and RGBA). Open window with "hello" * in its title bar. Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } |
Output: