├── 1 └── tutorial_1.c ├── 2 └── tutorial_2.c ├── 3 └── tutorial_3.c ├── 4 └── tutorial_4.c ├── 5 └── tutorial_5.c ├── 6 ├── data │ └── NeHe.bmp └── tutorial_6.c ├── 7 ├── data │ ├── Crate.bmp │ └── NeHe.bmp └── tutorial_7.c ├── 8 ├── data │ ├── Crate.bmp │ ├── Glass.bmp │ └── NeHe.bmp └── tutorial_8.c ├── 9 ├── data │ ├── Crate.bmp │ ├── Glass.bmp │ ├── NeHe.bmp │ ├── Star.bmp │ └── Star.png └── tutorial_9.c ├── 10 ├── data │ ├── Crate.bmp │ ├── Glass.bmp │ ├── Mud.bmp │ ├── NeHe.bmp │ ├── Star.bmp │ ├── Star.png │ └── World.txt └── tutorial_10.c ├── 11 ├── data │ └── Glass.bmp └── tutorial_11.c ├── .gitignore ├── Makefile ├── README.md └── data ├── Crate.bmp ├── Glass.bmp ├── Mud.bmp ├── NeHe.bmp ├── Star.bmp ├── Star.png └── World.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # OS Generated # 2 | .DS_Store* 3 | ehthumbs.db 4 | Icon? 5 | Thumbs.db 6 | *.swp 7 | 8 | #objects 9 | obj/ 10 | *.o 11 | 12 | #executable 13 | game 14 | tutorial 15 | NeHe 16 | */run 17 | -------------------------------------------------------------------------------- /1/tutorial_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int width, height; 7 | 8 | void init_gl(){ 9 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 10 | glLoadIdentity(); 11 | 12 | float aspect_ratio = ((float)height) / width; 13 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 14 | glMatrixMode(GL_MODELVIEW); 15 | 16 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 17 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 18 | glClearDepth(1.0f); // Depth Buffer Setup 19 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 20 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 21 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 22 | } 23 | 24 | int init(){ 25 | if( !glfwInit() ) 26 | { 27 | fprintf( stderr, "Failed to initialize GLFW\n" ); 28 | return -1; 29 | } 30 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 31 | 32 | width = 1024; 33 | height = 768; 34 | 35 | // Open a window and create its OpenGL context 36 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 37 | { 38 | fprintf( stderr, "Failed to open GLFW window\n" ); 39 | glfwTerminate(); 40 | return -1; 41 | } 42 | glfwSetWindowTitle( "Tutorial" ); 43 | glfwEnable( GLFW_STICKY_KEYS ); 44 | init_gl(); 45 | return 0; 46 | } 47 | 48 | int main(){ 49 | 50 | int status = init(); 51 | if(status) return status; 52 | 53 | do{ 54 | // Draw nothing, see you in tutorial 2 ! 55 | // Swap buffers 56 | glfwSwapBuffers(); 57 | 58 | } // Check if the ESC key was pressed or the window was closed 59 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 60 | glfwGetWindowParam( GLFW_OPENED ) ); 61 | } 62 | -------------------------------------------------------------------------------- /10/data/Crate.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/Crate.bmp -------------------------------------------------------------------------------- /10/data/Glass.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/Glass.bmp -------------------------------------------------------------------------------- /10/data/Mud.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/Mud.bmp -------------------------------------------------------------------------------- /10/data/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/NeHe.bmp -------------------------------------------------------------------------------- /10/data/Star.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/Star.bmp -------------------------------------------------------------------------------- /10/data/Star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/10/data/Star.png -------------------------------------------------------------------------------- /10/data/World.txt: -------------------------------------------------------------------------------- 1 | 2 | NUMPOLLIES 36 3 | 4 | // Floor 1 5 | -3.0 0.0 -3.0 0.0 6.0 6 | -3.0 0.0 3.0 0.0 0.0 7 | 3.0 0.0 3.0 6.0 0.0 8 | 9 | -3.0 0.0 -3.0 0.0 6.0 10 | 3.0 0.0 -3.0 6.0 6.0 11 | 3.0 0.0 3.0 6.0 0.0 12 | 13 | // Ceiling 1 14 | -3.0 1.0 -3.0 0.0 6.0 15 | -3.0 1.0 3.0 0.0 0.0 16 | 3.0 1.0 3.0 6.0 0.0 17 | -3.0 1.0 -3.0 0.0 6.0 18 | 3.0 1.0 -3.0 6.0 6.0 19 | 3.0 1.0 3.0 6.0 0.0 20 | 21 | // A1 22 | 23 | -2.0 1.0 -2.0 0.0 1.0 24 | -2.0 0.0 -2.0 0.0 0.0 25 | -0.5 0.0 -2.0 1.5 0.0 26 | -2.0 1.0 -2.0 0.0 1.0 27 | -0.5 1.0 -2.0 1.5 1.0 28 | -0.5 0.0 -2.0 1.5 0.0 29 | 30 | // A2 31 | 32 | 2.0 1.0 -2.0 2.0 1.0 33 | 2.0 0.0 -2.0 2.0 0.0 34 | 0.5 0.0 -2.0 0.5 0.0 35 | 2.0 1.0 -2.0 2.0 1.0 36 | 0.5 1.0 -2.0 0.5 1.0 37 | 0.5 0.0 -2.0 0.5 0.0 38 | 39 | // B1 40 | 41 | -2.0 1.0 2.0 2.0 1.0 42 | -2.0 0.0 2.0 2.0 0.0 43 | -0.5 0.0 2.0 0.5 0.0 44 | -2.0 1.0 2.0 2.0 1.0 45 | -0.5 1.0 2.0 0.5 1.0 46 | -0.5 0.0 2.0 0.5 0.0 47 | 48 | // B2 49 | 50 | 2.0 1.0 2.0 2.0 1.0 51 | 2.0 0.0 2.0 2.0 0.0 52 | 0.5 0.0 2.0 0.5 0.0 53 | 2.0 1.0 2.0 2.0 1.0 54 | 0.5 1.0 2.0 0.5 1.0 55 | 0.5 0.0 2.0 0.5 0.0 56 | 57 | // C1 58 | 59 | -2.0 1.0 -2.0 0.0 1.0 60 | -2.0 0.0 -2.0 0.0 0.0 61 | -2.0 0.0 -0.5 1.5 0.0 62 | -2.0 1.0 -2.0 0.0 1.0 63 | -2.0 1.0 -0.5 1.5 1.0 64 | -2.0 0.0 -0.5 1.5 0.0 65 | 66 | // C2 67 | 68 | -2.0 1.0 2.0 2.0 1.0 69 | -2.0 0.0 2.0 2.0 0.0 70 | -2.0 0.0 0.5 0.5 0.0 71 | -2.0 1.0 2.0 2.0 1.0 72 | -2.0 1.0 0.5 0.5 1.0 73 | -2.0 0.0 0.5 0.5 0.0 74 | 75 | // D1 76 | 77 | 2.0 1.0 -2.0 0.0 1.0 78 | 2.0 0.0 -2.0 0.0 0.0 79 | 2.0 0.0 -0.5 1.5 0.0 80 | 2.0 1.0 -2.0 0.0 1.0 81 | 2.0 1.0 -0.5 1.5 1.0 82 | 2.0 0.0 -0.5 1.5 0.0 83 | 84 | // D2 85 | 86 | 2.0 1.0 2.0 2.0 1.0 87 | 2.0 0.0 2.0 2.0 0.0 88 | 2.0 0.0 0.5 0.5 0.0 89 | 2.0 1.0 2.0 2.0 1.0 90 | 2.0 1.0 0.5 0.5 1.0 91 | 2.0 0.0 0.5 0.5 0.0 92 | 93 | // Upper hallway - L 94 | -0.5 1.0 -3.0 0.0 1.0 95 | -0.5 0.0 -3.0 0.0 0.0 96 | -0.5 0.0 -2.0 1.0 0.0 97 | -0.5 1.0 -3.0 0.0 1.0 98 | -0.5 1.0 -2.0 1.0 1.0 99 | -0.5 0.0 -2.0 1.0 0.0 100 | 101 | // Upper hallway - R 102 | 0.5 1.0 -3.0 0.0 1.0 103 | 0.5 0.0 -3.0 0.0 0.0 104 | 0.5 0.0 -2.0 1.0 0.0 105 | 0.5 1.0 -3.0 0.0 1.0 106 | 0.5 1.0 -2.0 1.0 1.0 107 | 0.5 0.0 -2.0 1.0 0.0 108 | 109 | // Lower hallway - L 110 | -0.5 1.0 3.0 0.0 1.0 111 | -0.5 0.0 3.0 0.0 0.0 112 | -0.5 0.0 2.0 1.0 0.0 113 | -0.5 1.0 3.0 0.0 1.0 114 | -0.5 1.0 2.0 1.0 1.0 115 | -0.5 0.0 2.0 1.0 0.0 116 | 117 | // Lower hallway - R 118 | 0.5 1.0 3.0 0.0 1.0 119 | 0.5 0.0 3.0 0.0 0.0 120 | 0.5 0.0 2.0 1.0 0.0 121 | 0.5 1.0 3.0 0.0 1.0 122 | 0.5 1.0 2.0 1.0 1.0 123 | 0.5 0.0 2.0 1.0 0.0 124 | 125 | 126 | // Left hallway - Lw 127 | 128 | -3.0 1.0 0.5 1.0 1.0 129 | -3.0 0.0 0.5 1.0 0.0 130 | -2.0 0.0 0.5 0.0 0.0 131 | -3.0 1.0 0.5 1.0 1.0 132 | -2.0 1.0 0.5 0.0 1.0 133 | -2.0 0.0 0.5 0.0 0.0 134 | 135 | // Left hallway - Hi 136 | 137 | -3.0 1.0 -0.5 1.0 1.0 138 | -3.0 0.0 -0.5 1.0 0.0 139 | -2.0 0.0 -0.5 0.0 0.0 140 | -3.0 1.0 -0.5 1.0 1.0 141 | -2.0 1.0 -0.5 0.0 1.0 142 | -2.0 0.0 -0.5 0.0 0.0 143 | 144 | // Right hallway - Lw 145 | 146 | 3.0 1.0 0.5 1.0 1.0 147 | 3.0 0.0 0.5 1.0 0.0 148 | 2.0 0.0 0.5 0.0 0.0 149 | 3.0 1.0 0.5 1.0 1.0 150 | 2.0 1.0 0.5 0.0 1.0 151 | 2.0 0.0 0.5 0.0 0.0 152 | 153 | // Right hallway - Hi 154 | 155 | 3.0 1.0 -0.5 1.0 1.0 156 | 3.0 0.0 -0.5 1.0 0.0 157 | 2.0 0.0 -0.5 0.0 0.0 158 | 3.0 1.0 -0.5 1.0 1.0 159 | 2.0 1.0 -0.5 0.0 1.0 160 | 2.0 0.0 -0.5 0.0 0.0 -------------------------------------------------------------------------------- /10/tutorial_10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int width, height; 9 | int light; // Lighting ON / OFF 10 | int filter; // Which Filter To Use 11 | int blend; 12 | GLfloat xrot; // X Rotation 13 | GLfloat yrot; // Y Rotation 14 | GLfloat xspeed; // X Rotation Speed 15 | GLfloat yspeed; // Y Rotation Speed 16 | GLfloat zspeed; // Y Rotation Speed 17 | GLfloat speed; // Y Rotation Speed 18 | GLfloat z=-5.0f; // Depth Into The Screen 19 | 20 | GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values ( NEW ) 21 | GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW ) 22 | GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position ( NEW ) 23 | 24 | const int num = 50; 25 | 26 | typedef struct // Create A Structure For Star 27 | { 28 | int r, g, b; // Stars Color 29 | GLfloat dist; // Stars Distance From Center 30 | GLfloat angle; // Stars Current Angle 31 | } 32 | stars; // Structures Name Is Stars 33 | stars star[num]; // Make 'star' Array Of 'num' Using Info From The Structure 'stars' 34 | 35 | GLfloat spin; // Spin Twinkling Stars 36 | 37 | GLuint loop; // General Loop Variable 38 | GLuint texture[3]; // Storage For One Texture 39 | 40 | typedef struct tagVERTEX // Build Our Vertex Structure 41 | { 42 | float x, y, z; // 3D Coordinates 43 | float u, v; // Texture Coordinates 44 | } VERTEX; // Call It VERTEX 45 | 46 | typedef struct tagTRIANGLE // Build Our Triangle Structure 47 | { 48 | VERTEX vertex[3]; // Array Of Three Vertices 49 | } TRIANGLE; // Call It TRIANGLE 50 | 51 | typedef struct tagSECTOR // Build Our Sector Structure 52 | { 53 | int numtriangles; // Number Of Triangles In Sector 54 | TRIANGLE* triangle; // Pointer To Array Of Triangles 55 | } SECTOR; // Call It SECTOR 56 | 57 | SECTOR sector1; 58 | GLfloat walkbias = 0; 59 | GLfloat walkbiasangle = 0; 60 | GLfloat lookupdown = 0.0; 61 | float heading, xpos, ypos, zpos; 62 | 63 | 64 | float rad(float angle) 65 | { 66 | return angle * 0.0174532925f; 67 | } 68 | 69 | 70 | void readstr(FILE *f, char *string) 71 | { 72 | do { 73 | fgets(string, 255, f); // read the line 74 | } while ((string[0] == '/') || (string[0] == '\n')); 75 | return; 76 | } 77 | 78 | // loads the world from a text file. 79 | void SetupWorld() 80 | { 81 | float x, y, z, u, v; 82 | int vert; 83 | int numtriangles; 84 | FILE *filein; // file to load the world from 85 | char oneline[255]; 86 | 87 | filein = fopen("data/world.txt", "rt"); 88 | 89 | readstr(filein, oneline); 90 | sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles); 91 | 92 | sector1.numtriangles = numtriangles; 93 | sector1.triangle = malloc(sizeof(TRIANGLE)*numtriangles); 94 | 95 | for (loop = 0; loop < numtriangles; loop++) { 96 | for (vert = 0; vert < 3; vert++) { 97 | readstr(filein,oneline); 98 | sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v); 99 | sector1.triangle[loop].vertex[vert].x = x; 100 | sector1.triangle[loop].vertex[vert].y = y; 101 | sector1.triangle[loop].vertex[vert].z = z; 102 | sector1.triangle[loop].vertex[vert].u = u; 103 | sector1.triangle[loop].vertex[vert].v = v; 104 | } 105 | } 106 | 107 | fclose(filein); 108 | return; 109 | } 110 | 111 | 112 | GLuint load_texture(char *filename) 113 | { 114 | return SOIL_load_OGL_texture 115 | ( 116 | filename, 117 | SOIL_LOAD_AUTO, 118 | SOIL_CREATE_NEW_ID, 119 | SOIL_FLAG_INVERT_Y 120 | ); 121 | } 122 | GLuint load_mipmap_texture(char *filename) 123 | { 124 | return SOIL_load_OGL_texture 125 | ( 126 | filename, 127 | SOIL_LOAD_AUTO, 128 | SOIL_CREATE_NEW_ID, 129 | SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y 130 | ); 131 | } 132 | 133 | int load() 134 | { 135 | /* load an image file directly as a new OpenGL texture */ 136 | texture[0] = load_texture("data/mud.bmp"); 137 | texture[1] = load_texture("data/mud.bmp"); 138 | texture[2] = load_mipmap_texture("data/mud.bmp"); 139 | if(texture[0] == 0) 140 | return 0; 141 | 142 | glBindTexture(GL_TEXTURE_2D, texture[0]); // 2d texture (x and y size) 143 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 144 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 145 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // scale cheaply when image bigger than texture 146 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // scale cheaply when image smalled than texture 147 | 148 | glBindTexture(GL_TEXTURE_2D, texture[1]); // 2d texture (x and y size) 149 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 150 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 151 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture 152 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture 153 | 154 | glBindTexture(GL_TEXTURE_2D, texture[2]); // 2d texture (x and y size) 155 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 156 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 157 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture 158 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // scale mipmap when image smalled than texture 159 | 160 | 161 | return 1; // Return Success 162 | } 163 | 164 | int update() 165 | { 166 | xpos += sin(rad(yrot))*speed; 167 | zpos += cos(rad(yrot))*speed; 168 | if (!light) glDisable(GL_LIGHTING); // Disable Lighting 169 | else glEnable(GL_LIGHTING); // Enable Lighting 170 | if(blend){ 171 | glEnable(GL_BLEND); // Turn Blending On 172 | //glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off 173 | } 174 | else{ 175 | glDisable(GL_BLEND); // Turn Blending Off 176 | //glEnable(GL_DEPTH_TEST); // Turn Depth Testing On 177 | } 178 | return 1; 179 | } 180 | 181 | int draw() // Here's Where We Do All The Drawing 182 | { 183 | glLoadIdentity(); 184 | int i; 185 | GLfloat x_m, y_m, z_m, u_m, v_m; 186 | ypos = .1; 187 | 188 | float sceneroty = 360-yrot; 189 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 190 | glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture 191 | glRotatef(sceneroty, 0, 1.f, 0); 192 | 193 | glTranslatef(-xpos, -ypos, -zpos); 194 | 195 | glBindTexture(GL_TEXTURE_2D, texture[filter]); 196 | 197 | for(i = 0; i < sector1.numtriangles; ++i){ 198 | glBegin(GL_TRIANGLES); 199 | glNormal3f( 0.0f, 0.0f, 1.0f); 200 | 201 | x_m = sector1.triangle[i].vertex[0].x; 202 | y_m = sector1.triangle[i].vertex[0].y; 203 | z_m = sector1.triangle[i].vertex[0].z; 204 | u_m = sector1.triangle[i].vertex[0].u; 205 | v_m = sector1.triangle[i].vertex[0].v; 206 | glTexCoord2f(u_m,v_m); 207 | glVertex3f(x_m,y_m,z_m); 208 | 209 | x_m = sector1.triangle[i].vertex[1].x; 210 | y_m = sector1.triangle[i].vertex[1].y; 211 | z_m = sector1.triangle[i].vertex[1].z; 212 | u_m = sector1.triangle[i].vertex[1].u; 213 | v_m = sector1.triangle[i].vertex[1].v; 214 | glTexCoord2f(u_m,v_m); 215 | glVertex3f(x_m,y_m,z_m); 216 | 217 | x_m = sector1.triangle[i].vertex[2].x; 218 | y_m = sector1.triangle[i].vertex[2].y; 219 | z_m = sector1.triangle[i].vertex[2].z; 220 | u_m = sector1.triangle[i].vertex[2].u; 221 | v_m = sector1.triangle[i].vertex[2].v; 222 | glTexCoord2f(u_m,v_m); 223 | glVertex3f(x_m,y_m,z_m); 224 | 225 | glEnd(); 226 | } 227 | glfwSwapBuffers(); 228 | return 1; 229 | } 230 | 231 | void key_poll() 232 | { 233 | speed = 0; 234 | if(glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) speed=-.2f; 235 | if(glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) speed=+.2f; 236 | if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) yrot-=1.5f; 237 | if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) yrot+=1.5f; 238 | if(glfwGetKey('0') == GLFW_PRESS) z+=.04f; 239 | if(glfwGetKey('1') == GLFW_PRESS) z-=.04f; 240 | } 241 | 242 | void key_press(int key) 243 | { 244 | switch(key){ 245 | case 'L':{ 246 | light = !light; 247 | break; 248 | } 249 | case 'F':{ 250 | filter = (filter+1)%3; 251 | break; 252 | } 253 | case 'B':{ 254 | blend = !blend; 255 | break; 256 | } 257 | default:{ 258 | break; 259 | } 260 | } 261 | } 262 | 263 | void key_release(int key) 264 | { 265 | return; 266 | } 267 | 268 | void GLFWCALL key_callback(int key, int action) 269 | { 270 | switch(action){ 271 | case GLFW_PRESS:{ 272 | key_press(key); 273 | break; 274 | } 275 | case GLFW_RELEASE:{ 276 | key_release(key); 277 | break; 278 | } 279 | default:{ 280 | break; 281 | } 282 | } 283 | } 284 | 285 | int init_gl(){ 286 | if(!load()) return 0; 287 | glEnable(GL_TEXTURE_2D); 288 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 289 | glLoadIdentity(); 290 | 291 | float aspect_ratio = ((float)height) / width; 292 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 293 | glMatrixMode(GL_MODELVIEW); 294 | 295 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 296 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 297 | glClearDepth(1.0f); // Depth Buffer Setup 298 | //glEnable(GL_DEPTH_TEST); // Enables Depth Testing 299 | //glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 300 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 301 | glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light 302 | glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light 303 | glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light 304 | glEnable(GL_LIGHT1); // Enable Light One 305 | glColor4f(1.0f,1.0f,1.0f,0.5f); // Full Brightness, 50% Alpha ( NEW ) 306 | glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW ) 307 | for (loop=0; loop 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int width, height; 9 | GLfloat xrot, yrot, zrot; 10 | GLuint texture[1]; // Storage For One Texture ( NEW ) 11 | float points[45][45][3]; 12 | int wiggle_count = 0; 13 | float hold; 14 | 15 | float rad(float degrees) 16 | { 17 | return degrees * 0.01745329252f; 18 | } 19 | 20 | float deg(float radians) 21 | { 22 | return radians * 57.295779513f; 23 | } 24 | 25 | int load() 26 | { 27 | /* load an image file directly as a new OpenGL texture */ 28 | texture[0] = SOIL_load_OGL_texture 29 | ( 30 | "data/Glass.bmp", 31 | SOIL_LOAD_AUTO, 32 | SOIL_CREATE_NEW_ID, 33 | SOIL_FLAG_INVERT_Y 34 | ); 35 | 36 | if(texture[0] == 0) 37 | return 0; 38 | 39 | // Typical Texture Generation Using Data From The Bitmap 40 | glBindTexture(GL_TEXTURE_2D, texture[0]); 41 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 42 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 43 | 44 | return 1; // Return Success 45 | } 46 | 47 | int draw(GLvoid) // Here's Where We Do All The Drawing 48 | { 49 | int x, y; // Loop Variables 50 | float float_x, float_y, float_xb, float_yb; // Used To Break The Flag Into Tiny Quads 51 | 52 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 53 | glLoadIdentity(); // Reset The Current Modelview Matrix 54 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And Depth Buffer 55 | glLoadIdentity(); // Reset The Current Matrix 56 | 57 | glTranslatef(0.0f,0.0f,-12.0f); // Translate 12 Units Into The Screen 58 | 59 | glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis 60 | glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis 61 | glRotatef(zrot,0.0f,0.0f,1.0f); // Rotate On The Z Axis 62 | 63 | glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture 64 | glBegin(GL_QUADS); // Start Drawing Our Quads 65 | for( x = 0; x < 44; x++ ) // Loop Through The X Plane (44 Points) 66 | { 67 | for( y = 0; y < 44; y++ ) // Loop Through The Y Plane (44 Points) 68 | { 69 | float_x = x/44.0f; // Create A Floating Point X Value 70 | float_y = y/44.0f; // Create A Floating Point Y Value 71 | float_xb = (x+1)/44.0f; // Create A Floating Point Y Value+0.0227f 72 | float_yb = (y+1)/44.0f; // Create A Floating Point Y Value+0.0227f 73 | glTexCoord2f( float_x, float_y); // First Texture Coordinate (Bottom Left) 74 | glVertex3f( points[x][y][0], points[x][y][1], points[x][y][2] ); 75 | 76 | glTexCoord2f( float_x, float_yb ); // Second Texture Coordinate (Top Left) 77 | glVertex3f( points[x][y+1][0], points[x][y+1][1], points[x][y+1][2] ); 78 | 79 | glTexCoord2f( float_xb, float_yb ); // Third Texture Coordinate (Top Right) 80 | glVertex3f( points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2] ); 81 | 82 | glTexCoord2f( float_xb, float_y ); // Fourth Texture Coordinate (Bottom Right) 83 | glVertex3f( points[x+1][y][0], points[x+1][y][1], points[x+1][y][2] ); 84 | } 85 | } 86 | glEnd(); // Done Drawing Our Quads 87 | if( wiggle_count == 2 ) // Used To Slow Down The Wave (Every 2nd Frame Only) 88 | { 89 | for( y = 0; y < 45; y++ ) // Loop Through The Y Plane 90 | { 91 | hold=points[0][y][2]; // Store Current Value One Left Side Of Wave 92 | for( x = 0; x < 44; x++) // Loop Through The X Plane 93 | { 94 | // Current Wave Value Equals Value To The Right 95 | points[x][y][2] = points[x+1][y][2]; 96 | } 97 | points[44][y][2]=hold; // Last Value Becomes The Far Left Stored Value 98 | } 99 | wiggle_count = 0; // Set Counter Back To Zero 100 | } 101 | wiggle_count++; // Increase The Counter 102 | xrot+=0.3f; // Increase The X Rotation Variable 103 | yrot+=0.2f; // Increase The Y Rotation Variable 104 | zrot+=0.4f; // Increase The Z Rotation Variable 105 | 106 | 107 | return 1; 108 | } 109 | 110 | int init_gl(){ 111 | if(!load()) return 0; 112 | glEnable(GL_TEXTURE_2D); 113 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 114 | glLoadIdentity(); 115 | 116 | float aspect_ratio = ((float)height) / width; 117 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 118 | glMatrixMode(GL_MODELVIEW); 119 | 120 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 121 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 122 | glClearDepth(1.0f); // Depth Buffer Setup 123 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 124 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 125 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 126 | glPolygonMode(GL_BACK, GL_FILL); 127 | glPolygonMode(GL_FRONT, GL_LINE); 128 | for(int x=0; x<45; x++) 129 | { 130 | // Loop Through The Y Plane 131 | for(int y=0; y<45; y++) 132 | { 133 | // Apply The Wave To Our Mesh 134 | points[x][y][0]=(x/5.0f)-4.5f; 135 | points[x][y][1]=(y/5.0f)-4.5f; 136 | points[x][y][2]=sin(rad((x/5.0f)*40.0f)); 137 | } 138 | } 139 | 140 | return 1; 141 | } 142 | 143 | int init(){ 144 | if( !glfwInit() ) 145 | { 146 | fprintf( stderr, "Failed to initialize GLFW\n" ); 147 | return 0; 148 | } 149 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 150 | 151 | width = 1024; 152 | height = 768; 153 | 154 | // Open a window and create its OpenGL context 155 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 156 | { 157 | fprintf( stderr, "Failed to open GLFW window\n" ); 158 | glfwTerminate(); 159 | return 0; 160 | } 161 | glfwSetWindowTitle( "Tutorial" ); 162 | glfwEnable( GLFW_STICKY_KEYS ); 163 | init_gl(); 164 | return 1; 165 | } 166 | 167 | int main(){ 168 | 169 | if(!init()) return -1; 170 | 171 | do{ 172 | // Draw nothing, see you in tutorial 2 ! 173 | draw(); 174 | // Swap buffers 175 | glfwSwapBuffers(); 176 | 177 | } // Check if the ESC key was pressed or the window was closed 178 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 179 | glfwGetWindowParam( GLFW_OPENED ) ); 180 | } 181 | -------------------------------------------------------------------------------- /2/tutorial_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int width, height; 7 | 8 | void init_gl(){ 9 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 10 | glLoadIdentity(); 11 | 12 | float aspect_ratio = ((float)height) / width; 13 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 14 | glMatrixMode(GL_MODELVIEW); 15 | 16 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 17 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 18 | glClearDepth(1.0f); // Depth Buffer Setup 19 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 20 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 21 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 22 | } 23 | 24 | int init(){ 25 | if( !glfwInit() ) 26 | { 27 | fprintf( stderr, "Failed to initialize GLFW\n" ); 28 | return -1; 29 | } 30 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 31 | 32 | width = 1024; 33 | height = 768; 34 | 35 | // Open a window and create its OpenGL context 36 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 37 | { 38 | fprintf( stderr, "Failed to open GLFW window\n" ); 39 | glfwTerminate(); 40 | return -1; 41 | } 42 | glfwSetWindowTitle( "Tutorial" ); 43 | glfwEnable( GLFW_STICKY_KEYS ); 44 | init_gl(); 45 | return 0; 46 | } 47 | 48 | void draw(GLvoid) // Here's Where We Do All The Drawing 49 | { 50 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 51 | glLoadIdentity(); // Reset The Current Modelview Matrix 52 | glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 53 | glBegin(GL_TRIANGLES); // Drawing Using Triangles 54 | 55 | glVertex3f( 0.0f, 1.0f, 0.0f); // Move Up One Unit From Center (Top Point) 56 | glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left) 57 | glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right) 58 | 59 | glEnd(); // Finished Drawing The Triangle 60 | glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units 61 | 62 | glBegin(GL_QUADS); // Draw A Quad 63 | glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left 64 | glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right 65 | glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right 66 | glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left 67 | glEnd(); // Done Drawing The Quad 68 | glLoadIdentity(); // Reset The Current Modelview Matrix 69 | 70 | } 71 | 72 | 73 | int main(){ 74 | 75 | int status = init(); 76 | if(status) return status; 77 | 78 | do{ 79 | // Draw nothing, see you in tutorial 2 ! 80 | draw(); 81 | // Swap buffers 82 | glfwSwapBuffers(); 83 | 84 | } // Check if the ESC key was pressed or the window was closed 85 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 86 | glfwGetWindowParam( GLFW_OPENED ) ); 87 | } 88 | -------------------------------------------------------------------------------- /3/tutorial_3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int width, height; 7 | 8 | void init_gl(){ 9 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 10 | glLoadIdentity(); 11 | 12 | float aspect_ratio = ((float)height) / width; 13 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 14 | glMatrixMode(GL_MODELVIEW); 15 | 16 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 17 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 18 | glClearDepth(1.0f); // Depth Buffer Setup 19 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 20 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 21 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 22 | } 23 | 24 | int init(){ 25 | if( !glfwInit() ) 26 | { 27 | fprintf( stderr, "Failed to initialize GLFW\n" ); 28 | return -1; 29 | } 30 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 31 | 32 | width = 1024; 33 | height = 768; 34 | 35 | // Open a window and create its OpenGL context 36 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 37 | { 38 | fprintf( stderr, "Failed to open GLFW window\n" ); 39 | glfwTerminate(); 40 | return -1; 41 | } 42 | glfwSetWindowTitle( "Tutorial" ); 43 | glfwEnable( GLFW_STICKY_KEYS ); 44 | init_gl(); 45 | return 0; 46 | } 47 | 48 | void draw(GLvoid) // Here's Where We Do All The Drawing 49 | { 50 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 51 | glLoadIdentity(); // Reset The Current Modelview Matrix 52 | glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 53 | glBegin(GL_TRIANGLES); // Drawing Using Triangles 54 | 55 | glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red 56 | glVertex3f( 0.0f, 1.0f, 0.0f); // Move Up One Unit From Center (Top Point) 57 | 58 | glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green 59 | glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left) 60 | 61 | glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue 62 | glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right) 63 | 64 | glEnd(); // Finished Drawing The Triangle 65 | glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units 66 | 67 | glColor3f(1.f,0.f,1.0f); // Set The Color To Blue One Time Only 68 | 69 | glBegin(GL_QUADS); // Draw A Quad 70 | glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left 71 | glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right 72 | glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right 73 | glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left 74 | glEnd(); // Done Drawing The Quad 75 | glLoadIdentity(); // Reset The Current Modelview Matrix 76 | 77 | } 78 | 79 | 80 | int main(){ 81 | 82 | int status = init(); 83 | if(status) return status; 84 | 85 | do{ 86 | // Draw nothing, see you in tutorial 2 ! 87 | draw(); 88 | // Swap buffers 89 | glfwSwapBuffers(); 90 | 91 | } // Check if the ESC key was pressed or the window was closed 92 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 93 | glfwGetWindowParam( GLFW_OPENED ) ); 94 | } 95 | -------------------------------------------------------------------------------- /4/tutorial_4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int width, height; 7 | GLfloat rtri; // Angle For The Triangle ( NEW ) 8 | GLfloat rquad; // Angle For The Quad ( NEW ) 9 | 10 | void draw(GLvoid) // Here's Where We Do All The Drawing 11 | { 12 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 13 | glLoadIdentity(); // Reset The Current Modelview Matrix 14 | glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 15 | glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW ) 16 | glBegin(GL_TRIANGLES); // Drawing Using Triangles 17 | 18 | glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red 19 | glVertex3f( 0.0f, 1.0f, 0.0f); // Move Up One Unit From Center (Top Point) 20 | 21 | glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green 22 | glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left) 23 | 24 | glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue 25 | glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right) 26 | 27 | glEnd(); // Finished Drawing The Triangle 28 | 29 | glLoadIdentity(); // Reset The Current Modelview Matrix 30 | glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0 31 | glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW ) 32 | 33 | glColor3f(1.f,0.f,1.0f); // Set The Color To Blue One Time Only 34 | 35 | glBegin(GL_QUADS); // Draw A Quad 36 | glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left 37 | glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right 38 | glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right 39 | glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left 40 | glEnd(); // Done Drawing The Quad 41 | glLoadIdentity(); // Reset The Current Modelview Matrix 42 | rtri+=0.6f; // Increase The Rotation Variable For The Triangle ( NEW ) 43 | rquad-=0.45f; // Decrease The Rotation Variable For The Quad ( NEW ) 44 | 45 | } 46 | 47 | void init_gl(){ 48 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 49 | glLoadIdentity(); 50 | 51 | float aspect_ratio = ((float)height) / width; 52 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 53 | glMatrixMode(GL_MODELVIEW); 54 | 55 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 56 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 57 | glClearDepth(1.0f); // Depth Buffer Setup 58 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 59 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 60 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 61 | } 62 | 63 | int init(){ 64 | if( !glfwInit() ) 65 | { 66 | fprintf( stderr, "Failed to initialize GLFW\n" ); 67 | return -1; 68 | } 69 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 70 | 71 | width = 1024; 72 | height = 768; 73 | 74 | // Open a window and create its OpenGL context 75 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 76 | { 77 | fprintf( stderr, "Failed to open GLFW window\n" ); 78 | glfwTerminate(); 79 | return -1; 80 | } 81 | glfwSetWindowTitle( "Tutorial" ); 82 | glfwEnable( GLFW_STICKY_KEYS ); 83 | init_gl(); 84 | return 0; 85 | } 86 | 87 | int main(){ 88 | 89 | int status = init(); 90 | if(status) return status; 91 | 92 | do{ 93 | // Draw nothing, see you in tutorial 2 ! 94 | draw(); 95 | // Swap buffers 96 | glfwSwapBuffers(); 97 | 98 | } // Check if the ESC key was pressed or the window was closed 99 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 100 | glfwGetWindowParam( GLFW_OPENED ) ); 101 | } 102 | -------------------------------------------------------------------------------- /5/tutorial_5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int width, height; 7 | GLfloat rtri; // Angle For The Triangle ( NEW ) 8 | GLfloat rquad; // Angle For The Quad ( NEW ) 9 | 10 | void draw(GLvoid) // Here's Where We Do All The Drawing 11 | { 12 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 13 | glLoadIdentity(); // Reset The Current Modelview Matrix 14 | glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 15 | glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW ) 16 | glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW ) 17 | glBegin(GL_TRIANGLES); // Drawing Using Triangles 18 | glColor3f(1.0f,0.0f,0.0f); // Red 19 | glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front) 20 | glColor3f(0.0f,1.0f,0.0f); // Green 21 | glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front) 22 | glColor3f(0.0f,0.0f,1.0f); // Blue 23 | glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front) 24 | glColor3f(1.0f,0.0f,0.0f); // Red 25 | glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right) 26 | glColor3f(0.0f,0.0f,1.0f); // Blue 27 | glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right) 28 | glColor3f(0.0f,1.0f,0.0f); // Green 29 | glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right) 30 | glColor3f(1.0f,0.0f,0.0f); // Red 31 | glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back) 32 | glColor3f(0.0f,1.0f,0.0f); // Green 33 | glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back) 34 | glColor3f(0.0f,0.0f,1.0f); // Blue 35 | glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back) 36 | glColor3f(1.0f,0.0f,0.0f); // Red 37 | glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left) 38 | glColor3f(0.0f,0.0f,1.0f); // Blue 39 | glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left) 40 | glColor3f(0.0f,1.0f,0.0f); // Green 41 | glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left) 42 | 43 | glEnd(); // Finished Drawing The Triangle 44 | 45 | glLoadIdentity(); // Reset The Current Modelview Matrix 46 | glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0 47 | glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW ) 48 | glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW ) 49 | 50 | glColor3f(1.f,0.f,1.0f); // Set The Color To Blue One Time Only 51 | 52 | glBegin(GL_QUADS); // Draw A Quad 53 | glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green 54 | glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top) 55 | glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top) 56 | glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top) 57 | glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top) 58 | glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange 59 | glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom) 60 | glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom) 61 | glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom) 62 | glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom) 63 | glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red 64 | glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front) 65 | glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front) 66 | glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front) 67 | glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front) 68 | glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow 69 | glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back) 70 | glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back) 71 | glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back) 72 | glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back) 73 | glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue 74 | glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left) 75 | glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) 76 | glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left) 77 | glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left) 78 | glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet 79 | glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right) 80 | glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right) 81 | glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right) 82 | glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right) 83 | 84 | glEnd(); // Done Drawing The Quad 85 | glLoadIdentity(); // Reset The Current Modelview Matrix 86 | rtri+=0.6f; // Increase The Rotation Variable For The Triangle ( NEW ) 87 | rquad-=0.45f; // Decrease The Rotation Variable For The Quad ( NEW ) 88 | 89 | } 90 | 91 | void init_gl(){ 92 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 93 | glLoadIdentity(); 94 | 95 | float aspect_ratio = ((float)height) / width; 96 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 97 | glMatrixMode(GL_MODELVIEW); 98 | 99 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 100 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 101 | glClearDepth(1.0f); // Depth Buffer Setup 102 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 103 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 104 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 105 | } 106 | 107 | int init(){ 108 | if( !glfwInit() ) 109 | { 110 | fprintf( stderr, "Failed to initialize GLFW\n" ); 111 | return -1; 112 | } 113 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 114 | 115 | width = 1024; 116 | height = 768; 117 | 118 | // Open a window and create its OpenGL context 119 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 120 | { 121 | fprintf( stderr, "Failed to open GLFW window\n" ); 122 | glfwTerminate(); 123 | return -1; 124 | } 125 | glfwSetWindowTitle( "Tutorial" ); 126 | glfwEnable( GLFW_STICKY_KEYS ); 127 | init_gl(); 128 | return 0; 129 | } 130 | 131 | int main(){ 132 | 133 | int status = init(); 134 | if(status) return status; 135 | 136 | do{ 137 | // Draw nothing, see you in tutorial 2 ! 138 | draw(); 139 | // Swap buffers 140 | glfwSwapBuffers(); 141 | 142 | } // Check if the ESC key was pressed or the window was closed 143 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 144 | glfwGetWindowParam( GLFW_OPENED ) ); 145 | } 146 | -------------------------------------------------------------------------------- /6/data/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/6/data/NeHe.bmp -------------------------------------------------------------------------------- /6/tutorial_6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int width, height; 8 | GLfloat xrot, yrot, zrot; 9 | GLuint texture[1]; // Storage For One Texture ( NEW ) 10 | 11 | int load() 12 | { 13 | /* load an image file directly as a new OpenGL texture */ 14 | texture[0] = SOIL_load_OGL_texture 15 | ( 16 | "data/NeHe.bmp", 17 | SOIL_LOAD_AUTO, 18 | SOIL_CREATE_NEW_ID, 19 | SOIL_FLAG_INVERT_Y 20 | ); 21 | 22 | if(texture[0] == 0) 23 | return 0; 24 | 25 | // Typical Texture Generation Using Data From The Bitmap 26 | glBindTexture(GL_TEXTURE_2D, texture[0]); 27 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 28 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 29 | 30 | return 1; // Return Success 31 | } 32 | 33 | int draw(GLvoid) // Here's Where We Do All The Drawing 34 | { 35 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 36 | glLoadIdentity(); // Reset The Current Modelview Matrix 37 | glTranslatef(0.0f,0.0f,-5.0f); // Move Left 1.5 Units And Into The Screen 6.0 38 | glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis 39 | glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis 40 | glRotatef(zrot,0.0f,0.0f,1.0f); // Rotate On The Z Axis 41 | glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture 42 | 43 | glBegin(GL_QUADS); 44 | // Front Face 45 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad 46 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad 47 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad 48 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad 49 | // Back Face 50 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad 51 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad 52 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad 53 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad 54 | // Top Face 55 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad 56 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad 57 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad 58 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad 59 | // Bottom Face 60 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad 61 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad 62 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad 63 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad 64 | // Right face 65 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad 66 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad 67 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad 68 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad 69 | // Left Face 70 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad 71 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad 72 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad 73 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad 74 | glEnd(); 75 | 76 | 77 | glLoadIdentity(); // Reset The Current Modelview Matrix 78 | xrot+=0.6f; // Increase The Rotation Variable For The Triangle ( NEW ) 79 | yrot+=1.4f; // Increase The Rotation Variable For The Triangle ( NEW ) 80 | zrot+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW ) 81 | return 1; 82 | } 83 | 84 | int init_gl(){ 85 | if(!load()) return 0; 86 | glEnable(GL_TEXTURE_2D); 87 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 88 | glLoadIdentity(); 89 | 90 | float aspect_ratio = ((float)height) / width; 91 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 92 | glMatrixMode(GL_MODELVIEW); 93 | 94 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 95 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 96 | glClearDepth(1.0f); // Depth Buffer Setup 97 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 98 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 99 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 100 | return 1; 101 | } 102 | 103 | int init(){ 104 | if( !glfwInit() ) 105 | { 106 | fprintf( stderr, "Failed to initialize GLFW\n" ); 107 | return 0; 108 | } 109 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 110 | 111 | width = 1024; 112 | height = 768; 113 | 114 | // Open a window and create its OpenGL context 115 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 116 | { 117 | fprintf( stderr, "Failed to open GLFW window\n" ); 118 | glfwTerminate(); 119 | return 0; 120 | } 121 | glfwSetWindowTitle( "Tutorial" ); 122 | glfwEnable( GLFW_STICKY_KEYS ); 123 | init_gl(); 124 | return 1; 125 | } 126 | 127 | int main(){ 128 | 129 | if(!init()) return -1; 130 | 131 | do{ 132 | // Draw nothing, see you in tutorial 2 ! 133 | draw(); 134 | // Swap buffers 135 | glfwSwapBuffers(); 136 | 137 | } // Check if the ESC key was pressed or the window was closed 138 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 139 | glfwGetWindowParam( GLFW_OPENED ) ); 140 | } 141 | -------------------------------------------------------------------------------- /7/data/Crate.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/7/data/Crate.bmp -------------------------------------------------------------------------------- /7/data/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/7/data/NeHe.bmp -------------------------------------------------------------------------------- /7/tutorial_7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int width, height; 8 | int light; // Lighting ON / OFF 9 | GLfloat xrot; // X Rotation 10 | GLfloat yrot; // Y Rotation 11 | GLfloat xspeed; // X Rotation Speed 12 | GLfloat yspeed; // Y Rotation Speed 13 | GLfloat z=-5.0f; // Depth Into The Screen 14 | 15 | GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values ( NEW ) 16 | GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW ) 17 | GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position ( NEW ) 18 | 19 | GLuint filter; // Which Filter To Use 20 | GLuint texture[3]; // Storage for 3 textures 21 | 22 | GLuint load_texture(char *filename) 23 | { 24 | return SOIL_load_OGL_texture 25 | ( 26 | filename, 27 | SOIL_LOAD_AUTO, 28 | SOIL_CREATE_NEW_ID, 29 | SOIL_FLAG_INVERT_Y 30 | ); 31 | } 32 | GLuint load_mipmap_texture(char *filename) 33 | { 34 | return SOIL_load_OGL_texture 35 | ( 36 | filename, 37 | SOIL_LOAD_AUTO, 38 | SOIL_CREATE_NEW_ID, 39 | SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y 40 | ); 41 | } 42 | 43 | int load() 44 | { 45 | /* load an image file directly as a new OpenGL texture */ 46 | texture[0] = load_texture("data/Crate.bmp"); 47 | texture[1] = load_texture("data/Crate.bmp"); 48 | texture[2] = load_mipmap_texture("data/Crate.bmp"); 49 | if(texture[0] == 0) 50 | return 0; 51 | 52 | // Create Nearest Filtered Texture 53 | glBindTexture(GL_TEXTURE_2D, texture[0]); 54 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) 55 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) 56 | 57 | // Create Linear Filtered Texture 58 | glBindTexture(GL_TEXTURE_2D, texture[1]); 59 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 60 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 61 | 62 | // Create MipMapped Texture 63 | glBindTexture(GL_TEXTURE_2D, texture[2]); 64 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 65 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW ) 66 | 67 | return 1; // Return Success 68 | } 69 | 70 | int draw(GLvoid) // Here's Where We Do All The Drawing 71 | { 72 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 73 | glLoadIdentity(); // Reset The View 74 | glTranslatef(0.0f,0.0f,z); // Translate Into/Out Of The Screen By z 75 | 76 | glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis By xrot 77 | glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis By yrot 78 | glBindTexture(GL_TEXTURE_2D, texture[filter]); // Select A Texture Based On filter 79 | 80 | glBegin(GL_QUADS); // Start Drawing Quads 81 | 82 | // Front Face 83 | glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer 84 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 1 (Front) 85 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 2 (Front) 86 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Front) 87 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 4 (Front) 88 | // Back Face 89 | glNormal3f( 0.0f, 0.0f,-1.0f); // Normal Pointing Away From Viewer 90 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Back) 91 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 2 (Back) 92 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 3 (Back) 93 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 4 (Back) 94 | // Top Face 95 | glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up 96 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 1 (Top) 97 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 2 (Top) 98 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Top) 99 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 4 (Top) 100 | // Bottom Face 101 | glNormal3f( 0.0f,-1.0f, 0.0f); // Normal Pointing Down 102 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Bottom) 103 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 2 (Bottom) 104 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 3 (Bottom) 105 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 4 (Bottom) 106 | // Right face 107 | glNormal3f( 1.0f, 0.0f, 0.0f); // Normal Pointing Right 108 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 1 (Right) 109 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 2 (Right) 110 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Right) 111 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 4 (Right) 112 | // Left Face 113 | glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Pointing Left 114 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Left) 115 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 2 (Left) 116 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 3 (Left) 117 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 4 (Left) 118 | glEnd(); // Done Drawing Quads 119 | 120 | xrot+=xspeed; // Add xspeed To xrot 121 | yrot+=yspeed; // Add yspeed To yrot 122 | 123 | 124 | 125 | return 1; 126 | } 127 | 128 | void key_press(int key) 129 | { 130 | switch(key){ 131 | case 'L':{ 132 | light = !light; 133 | break; 134 | } 135 | case 'F':{ 136 | filter = (filter+1)%3; 137 | break; 138 | } 139 | default:{ 140 | break; 141 | } 142 | } 143 | } 144 | 145 | void key_release(int key) 146 | { 147 | return; 148 | } 149 | 150 | void GLFWCALL key_callback(int key, int action) 151 | { 152 | switch(action){ 153 | case GLFW_PRESS:{ 154 | key_press(key); 155 | break; 156 | } 157 | case GLFW_RELEASE:{ 158 | key_release(key); 159 | break; 160 | } 161 | default:{ 162 | break; 163 | } 164 | } 165 | } 166 | int init_gl(){ 167 | if(!load()) return 0; 168 | glEnable(GL_TEXTURE_2D); 169 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 170 | glLoadIdentity(); 171 | 172 | float aspect_ratio = ((float)height) / width; 173 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 174 | glMatrixMode(GL_MODELVIEW); 175 | 176 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 177 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 178 | glClearDepth(1.0f); // Depth Buffer Setup 179 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 180 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 181 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 182 | glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light 183 | glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light 184 | glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light 185 | glEnable(GL_LIGHT1); // Enable Light One 186 | 187 | return 1; 188 | } 189 | 190 | int init(){ 191 | if( !glfwInit() ) 192 | { 193 | fprintf( stderr, "Failed to initialize GLFW\n" ); 194 | return 0; 195 | } 196 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 197 | 198 | width = 1024; 199 | height = 768; 200 | 201 | // Open a window and create its OpenGL context 202 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 203 | { 204 | fprintf( stderr, "Failed to open GLFW window\n" ); 205 | glfwTerminate(); 206 | return 0; 207 | } 208 | glfwSetWindowTitle( "Tutorial" ); 209 | //glfwEnable( GLFW_STICKY_KEYS ); 210 | glfwSetKeyCallback(key_callback); 211 | if(!init_gl()) return 0; 212 | return 1; 213 | } 214 | 215 | int main(){ 216 | 217 | if(!init()) return -1; 218 | 219 | do{ 220 | if(glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) xspeed-=.04f; 221 | if(glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) xspeed+=.04f; 222 | if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) yspeed+=.04f; 223 | if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) yspeed-=.04f; 224 | if(glfwGetKey('0') == GLFW_PRESS) z+=.04f; 225 | if(glfwGetKey('1') == GLFW_PRESS) z-=.04f; 226 | // Draw nothing, see you in tutorial 2 ! 227 | if (!light) glDisable(GL_LIGHTING); // Disable Lighting 228 | else glEnable(GL_LIGHTING); // Enable Lighting 229 | 230 | draw(); 231 | // Swap buffers 232 | glfwSwapBuffers(); 233 | 234 | } // Check if the ESC key was pressed or the window was closed 235 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 236 | glfwGetWindowParam( GLFW_OPENED ) ); 237 | } 238 | -------------------------------------------------------------------------------- /8/data/Crate.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/8/data/Crate.bmp -------------------------------------------------------------------------------- /8/data/Glass.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/8/data/Glass.bmp -------------------------------------------------------------------------------- /8/data/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/8/data/NeHe.bmp -------------------------------------------------------------------------------- /8/tutorial_8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int width, height; 8 | int light; // Lighting ON / OFF 9 | int filter; // Which Filter To Use 10 | int blend; 11 | GLfloat xrot; // X Rotation 12 | GLfloat yrot; // Y Rotation 13 | GLfloat xspeed; // X Rotation Speed 14 | GLfloat yspeed; // Y Rotation Speed 15 | GLfloat z=-5.0f; // Depth Into The Screen 16 | 17 | GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values ( NEW ) 18 | GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW ) 19 | GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position ( NEW ) 20 | 21 | GLuint texture[3]; // Storage for 3 textures 22 | 23 | GLuint load_texture(char *filename) 24 | { 25 | return SOIL_load_OGL_texture 26 | ( 27 | filename, 28 | SOIL_LOAD_AUTO, 29 | SOIL_CREATE_NEW_ID, 30 | SOIL_FLAG_INVERT_Y 31 | ); 32 | } 33 | GLuint load_mipmap_texture(char *filename) 34 | { 35 | return SOIL_load_OGL_texture 36 | ( 37 | filename, 38 | SOIL_LOAD_AUTO, 39 | SOIL_CREATE_NEW_ID, 40 | SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y 41 | ); 42 | } 43 | 44 | int load() 45 | { 46 | /* load an image file directly as a new OpenGL texture */ 47 | texture[0] = load_texture("data/Glass.bmp"); 48 | texture[1] = load_texture("data/Glass.bmp"); 49 | texture[2] = load_mipmap_texture("data/Glass.bmp"); 50 | if(texture[0] == 0) 51 | return 0; 52 | 53 | // Create Nearest Filtered Texture 54 | glBindTexture(GL_TEXTURE_2D, texture[0]); 55 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) 56 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) 57 | 58 | // Create Linear Filtered Texture 59 | glBindTexture(GL_TEXTURE_2D, texture[1]); 60 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 61 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 62 | 63 | // Create MipMapped Texture 64 | glBindTexture(GL_TEXTURE_2D, texture[2]); 65 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 66 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW ) 67 | 68 | return 1; // Return Success 69 | } 70 | 71 | int draw(GLvoid) // Here's Where We Do All The Drawing 72 | { 73 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 74 | glLoadIdentity(); // Reset The View 75 | glTranslatef(0.0f,0.0f,z); // Translate Into/Out Of The Screen By z 76 | 77 | glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis By xrot 78 | glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis By yrot 79 | glBindTexture(GL_TEXTURE_2D, texture[filter]); // Select A Texture Based On filter 80 | 81 | glBegin(GL_QUADS); // Start Drawing Quads 82 | 83 | // Front Face 84 | glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer 85 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 1 (Front) 86 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 2 (Front) 87 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Front) 88 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 4 (Front) 89 | // Back Face 90 | glNormal3f( 0.0f, 0.0f,-1.0f); // Normal Pointing Away From Viewer 91 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Back) 92 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 2 (Back) 93 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 3 (Back) 94 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 4 (Back) 95 | // Top Face 96 | glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up 97 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 1 (Top) 98 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 2 (Top) 99 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Top) 100 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 4 (Top) 101 | // Bottom Face 102 | glNormal3f( 0.0f,-1.0f, 0.0f); // Normal Pointing Down 103 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Bottom) 104 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 2 (Bottom) 105 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 3 (Bottom) 106 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 4 (Bottom) 107 | // Right face 108 | glNormal3f( 1.0f, 0.0f, 0.0f); // Normal Pointing Right 109 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Point 1 (Right) 110 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Point 2 (Right) 111 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Point 3 (Right) 112 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Point 4 (Right) 113 | // Left Face 114 | glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Pointing Left 115 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Point 1 (Left) 116 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Point 2 (Left) 117 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Point 3 (Left) 118 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Point 4 (Left) 119 | glEnd(); // Done Drawing Quads 120 | 121 | xrot+=xspeed; // Add xspeed To xrot 122 | yrot+=yspeed; // Add yspeed To yrot 123 | glLoadIdentity(); // Reset The View 124 | 125 | return 1; 126 | } 127 | 128 | void key_press(int key) 129 | { 130 | switch(key){ 131 | case 'L':{ 132 | light = !light; 133 | break; 134 | } 135 | case 'F':{ 136 | filter = (filter+1)%3; 137 | break; 138 | } 139 | case 'B':{ 140 | blend = !blend; 141 | break; 142 | } 143 | default:{ 144 | break; 145 | } 146 | } 147 | } 148 | 149 | void key_release(int key) 150 | { 151 | return; 152 | } 153 | 154 | void GLFWCALL key_callback(int key, int action) 155 | { 156 | switch(action){ 157 | case GLFW_PRESS:{ 158 | key_press(key); 159 | break; 160 | } 161 | case GLFW_RELEASE:{ 162 | key_release(key); 163 | break; 164 | } 165 | default:{ 166 | break; 167 | } 168 | } 169 | } 170 | 171 | int init_gl(){ 172 | if(!load()) return 0; 173 | glEnable(GL_TEXTURE_2D); 174 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 175 | glLoadIdentity(); 176 | 177 | float aspect_ratio = ((float)height) / width; 178 | gluPerspective(45.0f,(1.f/aspect_ratio),0.1f,100.0f); 179 | glMatrixMode(GL_MODELVIEW); 180 | 181 | glShadeModel(GL_SMOOTH); // Enables Smooth Shading 182 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 183 | glClearDepth(1.0f); // Depth Buffer Setup 184 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing 185 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do 186 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 187 | glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light 188 | glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light 189 | glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light 190 | glEnable(GL_LIGHT1); // Enable Light One 191 | glColor4f(1.0f,1.0f,1.0f,0.5f); // Full Brightness, 50% Alpha ( NEW ) 192 | glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW ) 193 | 194 | return 1; 195 | } 196 | 197 | int init(){ 198 | if( !glfwInit() ) 199 | { 200 | fprintf( stderr, "Failed to initialize GLFW\n" ); 201 | return 0; 202 | } 203 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing 204 | 205 | width = 1024; 206 | height = 768; 207 | 208 | // Open a window and create its OpenGL context 209 | if( !glfwOpenWindow( width, height, 0,0,0,0, 32,0, GLFW_WINDOW ) ) 210 | { 211 | fprintf( stderr, "Failed to open GLFW window\n" ); 212 | glfwTerminate(); 213 | return 0; 214 | } 215 | glfwSetWindowTitle( "Tutorial" ); 216 | //glfwEnable( GLFW_STICKY_KEYS ); 217 | glfwSetKeyCallback(key_callback); 218 | if(!init_gl()) return 0; 219 | return 1; 220 | } 221 | 222 | int main(){ 223 | 224 | if(!init()) return -1; 225 | 226 | do{ 227 | if(glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) xspeed-=.04f; 228 | if(glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) xspeed+=.04f; 229 | if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) yspeed+=.04f; 230 | if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) yspeed-=.04f; 231 | if(glfwGetKey('0') == GLFW_PRESS) z+=.04f; 232 | if(glfwGetKey('1') == GLFW_PRESS) z-=.04f; 233 | // Draw nothing, see you in tutorial 2 ! 234 | if (!light) glDisable(GL_LIGHTING); // Disable Lighting 235 | else glEnable(GL_LIGHTING); // Enable Lighting 236 | if(blend){ 237 | glEnable(GL_BLEND); // Turn Blending On 238 | glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off 239 | } 240 | else{ 241 | glDisable(GL_BLEND); // Turn Blending Off 242 | glEnable(GL_DEPTH_TEST); // Turn Depth Testing On 243 | } 244 | 245 | 246 | draw(); 247 | // Swap buffers 248 | glfwSwapBuffers(); 249 | 250 | } // Check if the ESC key was pressed or the window was closed 251 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && 252 | glfwGetWindowParam( GLFW_OPENED ) ); 253 | } 254 | -------------------------------------------------------------------------------- /9/data/Crate.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/9/data/Crate.bmp -------------------------------------------------------------------------------- /9/data/Glass.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/9/data/Glass.bmp -------------------------------------------------------------------------------- /9/data/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/9/data/NeHe.bmp -------------------------------------------------------------------------------- /9/data/Star.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/9/data/Star.bmp -------------------------------------------------------------------------------- /9/data/Star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjreddie/NeHe-Tutorials-Using-GLFW/916539910df52c1949071d394d122a71af63f3e9/9/data/Star.png -------------------------------------------------------------------------------- /9/tutorial_9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int width, height; 8 | int light; // Lighting ON / OFF 9 | int filter; // Which Filter To Use 10 | int blend; 11 | int twinkle; 12 | GLfloat xrot; // X Rotation 13 | GLfloat yrot; // Y Rotation 14 | GLfloat xspeed; // X Rotation Speed 15 | GLfloat yspeed; // Y Rotation Speed 16 | GLfloat z=-5.0f; // Depth Into The Screen 17 | 18 | GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values ( NEW ) 19 | GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW ) 20 | GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position ( NEW ) 21 | 22 | const int num = 50; 23 | 24 | typedef struct // Create A Structure For Star 25 | { 26 | int r, g, b; // Stars Color 27 | GLfloat dist; // Stars Distance From Center 28 | GLfloat angle; // Stars Current Angle 29 | } 30 | stars; // Structures Name Is Stars 31 | stars star[num]; // Make 'star' Array Of 'num' Using Info From The Structure 'stars' 32 | 33 | GLfloat spin; // Spin Twinkling Stars 34 | 35 | GLuint loop; // General Loop Variable 36 | GLuint texture[1]; // Storage For One Texture 37 | 38 | 39 | GLuint load_texture(char *filename) 40 | { 41 | return SOIL_load_OGL_texture 42 | ( 43 | filename, 44 | SOIL_LOAD_AUTO, 45 | SOIL_CREATE_NEW_ID, 46 | SOIL_FLAG_INVERT_Y 47 | ); 48 | } 49 | GLuint load_mipmap_texture(char *filename) 50 | { 51 | return SOIL_load_OGL_texture 52 | ( 53 | filename, 54 | SOIL_LOAD_AUTO, 55 | SOIL_CREATE_NEW_ID, 56 | SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y 57 | ); 58 | } 59 | 60 | int load() 61 | { 62 | /* load an image file directly as a new OpenGL texture */ 63 | texture[0] = load_texture("data/Star.png"); 64 | if(texture[0] == 0) 65 | return 0; 66 | 67 | // Create Linear Filtered Texture 68 | glBindTexture(GL_TEXTURE_2D, texture[0]); 69 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 70 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 71 | 72 | return 1; // Return Success 73 | } 74 | 75 | int draw(GLvoid) // Here's Where We Do All The Drawing 76 | { 77 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 78 | glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture 79 | 80 | for (loop=0; loop