test/testshader.c
changeset 7663 53fe1b64eb2d
parent 7639 9406b7dd2f2d
child 7996 be1526907541
equal deleted inserted replaced
7662:d31efd717578 7663:53fe1b64eb2d
   330 
   330 
   331     return texture;
   331     return texture;
   332 }
   332 }
   333 
   333 
   334 /* A general OpenGL initialization function.    Sets all of the initial parameters. */
   334 /* A general OpenGL initialization function.    Sets all of the initial parameters. */
   335 void InitGL(int Width, int Height)                    // We call this right after our OpenGL window is created.
   335 void InitGL(int Width, int Height)                    /* We call this right after our OpenGL window is created. */
   336 {
   336 {
   337     GLdouble aspect;
   337     GLdouble aspect;
   338 
   338 
   339     glViewport(0, 0, Width, Height);
   339     glViewport(0, 0, Width, Height);
   340     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);        // This Will Clear The Background Color To Black
   340     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);        /* This Will Clear The Background Color To Black */
   341     glClearDepth(1.0);                // Enables Clearing Of The Depth Buffer
   341     glClearDepth(1.0);                /* Enables Clearing Of The Depth Buffer */
   342     glDepthFunc(GL_LESS);                // The Type Of Depth Test To Do
   342     glDepthFunc(GL_LESS);                /* The Type Of Depth Test To Do */
   343     glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
   343     glEnable(GL_DEPTH_TEST);            /* Enables Depth Testing */
   344     glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading
   344     glShadeModel(GL_SMOOTH);            /* Enables Smooth Color Shading */
   345 
   345 
   346     glMatrixMode(GL_PROJECTION);
   346     glMatrixMode(GL_PROJECTION);
   347     glLoadIdentity();                // Reset The Projection Matrix
   347     glLoadIdentity();                /* Reset The Projection Matrix */
   348 
   348 
   349     aspect = (GLdouble)Width / Height;
   349     aspect = (GLdouble)Width / Height;
   350     glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
   350     glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
   351 
   351 
   352     glMatrixMode(GL_MODELVIEW);
   352     glMatrixMode(GL_MODELVIEW);
   361         MINY,
   361         MINY,
   362         MAXX,
   362         MAXX,
   363         MAXY
   363         MAXY
   364     };
   364     };
   365 
   365 
   366     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear The Screen And The Depth Buffer
   366     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        /* Clear The Screen And The Depth Buffer */
   367     glLoadIdentity();                // Reset The View
   367     glLoadIdentity();                /* Reset The View */
   368 
   368 
   369     glTranslatef(-1.5f,0.0f,0.0f);        // Move Left 1.5 Units
   369     glTranslatef(-1.5f,0.0f,0.0f);        /* Move Left 1.5 Units */
   370 
   370 
   371     // draw a triangle (in smooth coloring mode)
   371     /* draw a triangle (in smooth coloring mode) */
   372     glBegin(GL_POLYGON);                // start drawing a polygon
   372     glBegin(GL_POLYGON);                /* start drawing a polygon */
   373     glColor3f(1.0f,0.0f,0.0f);            // Set The Color To Red
   373     glColor3f(1.0f,0.0f,0.0f);            /* Set The Color To Red */
   374     glVertex3f( 0.0f, 1.0f, 0.0f);        // Top
   374     glVertex3f( 0.0f, 1.0f, 0.0f);        /* Top */
   375     glColor3f(0.0f,1.0f,0.0f);            // Set The Color To Green
   375     glColor3f(0.0f,1.0f,0.0f);            /* Set The Color To Green */
   376     glVertex3f( 1.0f,-1.0f, 0.0f);        // Bottom Right
   376     glVertex3f( 1.0f,-1.0f, 0.0f);        /* Bottom Right */
   377     glColor3f(0.0f,0.0f,1.0f);            // Set The Color To Blue
   377     glColor3f(0.0f,0.0f,1.0f);            /* Set The Color To Blue */
   378     glVertex3f(-1.0f,-1.0f, 0.0f);        // Bottom Left
   378     glVertex3f(-1.0f,-1.0f, 0.0f);        /* Bottom Left */
   379     glEnd();                    // we're done with the polygon (smooth color interpolation)
   379     glEnd();                    /* we're done with the polygon (smooth color interpolation) */
   380 
   380 
   381     glTranslatef(3.0f,0.0f,0.0f);         // Move Right 3 Units
   381     glTranslatef(3.0f,0.0f,0.0f);         /* Move Right 3 Units */
   382 
   382 
   383     // Enable blending
   383     /* Enable blending */
   384     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   384     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   385     glEnable(GL_BLEND);
   385     glEnable(GL_BLEND);
   386     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   386     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   387 
   387 
   388     // draw a textured square (quadrilateral)
   388     /* draw a textured square (quadrilateral) */
   389     glEnable(GL_TEXTURE_2D);
   389     glEnable(GL_TEXTURE_2D);
   390     glBindTexture(GL_TEXTURE_2D, texture);
   390     glBindTexture(GL_TEXTURE_2D, texture);
   391     glColor3f(1.0f,1.0f,1.0f);
   391     glColor3f(1.0f,1.0f,1.0f);
   392     if (shaders_supported) {
   392     if (shaders_supported) {
   393         glUseProgramObjectARB(shaders[current_shader].program);
   393         glUseProgramObjectARB(shaders[current_shader].program);
   394     }
   394     }
   395 
   395 
   396     glBegin(GL_QUADS);                // start drawing a polygon (4 sided)
   396     glBegin(GL_QUADS);                /* start drawing a polygon (4 sided) */
   397     glTexCoord2f(texcoord[MINX], texcoord[MINY]);
   397     glTexCoord2f(texcoord[MINX], texcoord[MINY]);
   398     glVertex3f(-1.0f, 1.0f, 0.0f);        // Top Left
   398     glVertex3f(-1.0f, 1.0f, 0.0f);        /* Top Left */
   399     glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
   399     glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
   400     glVertex3f( 1.0f, 1.0f, 0.0f);        // Top Right
   400     glVertex3f( 1.0f, 1.0f, 0.0f);        /* Top Right */
   401     glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
   401     glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
   402     glVertex3f( 1.0f,-1.0f, 0.0f);        // Bottom Right
   402     glVertex3f( 1.0f,-1.0f, 0.0f);        /* Bottom Right */
   403     glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
   403     glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
   404     glVertex3f(-1.0f,-1.0f, 0.0f);        // Bottom Left
   404     glVertex3f(-1.0f,-1.0f, 0.0f);        /* Bottom Left */
   405     glEnd();                    // done with the polygon
   405     glEnd();                    /* done with the polygon */
   406 
   406 
   407     if (shaders_supported) {
   407     if (shaders_supported) {
   408         glUseProgramObjectARB(0);
   408         glUseProgramObjectARB(0);
   409     }
   409     }
   410     glDisable(GL_TEXTURE_2D);
   410     glDisable(GL_TEXTURE_2D);
   411 
   411 
   412     // swap buffers to display, since we're double buffered.
   412     /* swap buffers to display, since we're double buffered. */
   413     SDL_GL_SwapWindow(window);
   413     SDL_GL_SwapWindow(window);
   414 }
   414 }
   415 
   415 
   416 int main(int argc, char **argv)
   416 int main(int argc, char **argv)
   417 {
   417 {