Created
December 2, 2011 17:53
-
-
Save davidwparker/1424169 to your computer and use it in GitHub Desktop.
OpenGL Screencast 18: Overlays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "screencasts.h" | |
| /* | |
| * main() | |
| * ---- | |
| * Start up GLUT and tell it what to do | |
| */ | |
| int main(int argc,char* argv[]) | |
| { | |
| initializeGlobals(); | |
| /* screencast specific variables */ | |
| windowName = "OpenGL screenscasts 18: Overlays"; | |
| screencastID = 18; | |
| toggleAxes = 0; | |
| toggleAnimation = 0; | |
| glutInit(&argc,argv); | |
| glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
| glutInitWindowSize(windowWidth,windowHeight); | |
| glutInitWindowPosition(450,350); | |
| glutCreateWindow(windowName); | |
| glutDisplayFunc(display); | |
| glutReshapeFunc(displayReshape); | |
| glutKeyboardFunc(windowKey); | |
| glutSpecialFunc(windowSpecial); | |
| initializeTextures(); | |
| initializeObjs(); | |
| timer(toggleAnimation); | |
| redisplayAll(); | |
| glutMainLoop(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * drawOverlay() | |
| * ------ | |
| * Our overlay is just a 2D picture placed over the 3D scene | |
| */ | |
| void drawOverlay(void) | |
| { | |
| if (toggleOverlay) { | |
| glDisable(GL_LIGHTING); | |
| // Save transform attributes (Matrix Mode and Enabled Modes) | |
| glPushAttrib(GL_TRANSFORM_BIT|GL_ENABLE_BIT); | |
| // Save projection matrix and set unit transform | |
| glMatrixMode(GL_PROJECTION); | |
| glPushMatrix(); | |
| glLoadIdentity(); | |
| glOrtho(-asp,+asp,-1,1,-1,1); | |
| // Save model view matrix and set to identity | |
| glMatrixMode(GL_MODELVIEW); | |
| glPushMatrix(); | |
| glLoadIdentity(); | |
| // Draw bottom with texture | |
| glColor3f(1,1,1); | |
| glEnable(GL_TEXTURE_2D); | |
| glBindTexture(GL_TEXTURE_2D,currentTexture); | |
| glBegin(GL_QUADS); | |
| glTexCoord2d(0,0);glVertex2f(-2,-1); | |
| glTexCoord2d(1,0);glVertex2f(+2,-1); | |
| glTexCoord2d(1,1);glVertex2f(+2, 0); | |
| glTexCoord2d(0,1);glVertex2f(-2, 0); | |
| glEnd(); | |
| glDisable(GL_TEXTURE_2D); | |
| // Draw the inside in grey | |
| glColor3f(0.6,0.6,0.6); | |
| glBegin(GL_QUADS); | |
| // Left | |
| glVertex2f(-2,-1); | |
| glVertex2f(-2,+1); | |
| glVertex2f(-8,+1); | |
| glVertex2f(-8,-1); | |
| // Right | |
| glVertex2f(+2,-1); | |
| glVertex2f(+2,+1); | |
| glVertex2f(+8,+1); | |
| glVertex2f(+8,-1); | |
| // Left overhead | |
| glVertex2f(-2.00,+0.8); | |
| glVertex2f(-2.00,+1); | |
| glVertex2f(-0.02,+1); | |
| glVertex2f(-0.02,+0.9); | |
| // Right overhead | |
| glVertex2f(+2.00,+0.8); | |
| glVertex2f(+2.00,+1); | |
| glVertex2f(+0.02,+1); | |
| glVertex2f(+0.02,+0.9); | |
| // Middle divider | |
| glVertex2f(-0.02,+1); | |
| glVertex2f(+0.02,+1); | |
| glVertex2f(+0.02,+0); | |
| glVertex2f(-0.02,+0); | |
| glEnd(); | |
| // Reset model view matrix | |
| glPopMatrix(); | |
| // Reset projection matrix | |
| glMatrixMode(GL_PROJECTION); | |
| glPopMatrix(); | |
| // Pop transform attributes (Matrix Mode and Enabled Modes) | |
| glPopAttrib(); | |
| if (toggleLight) glEnable(GL_LIGHTING); | |
| } | |
| } | |
| /* | |
| * drawScene() | |
| * ------ | |
| * Draws the scene with everything we need in it | |
| */ | |
| void drawScene(void) | |
| { | |
| int i; | |
| drawAxes(); | |
| drawParameters(); | |
| currentTexture = textures[TEX_DEFAULT]; | |
| drawLight(); | |
| currentTexture = textures[TEX_CRATE]; | |
| for (i = 0; i < Length(cubes); i++) | |
| drawCube(cubes[i]); | |
| /* This must be drawn last */ | |
| currentTexture = textures[TEX_VENUS]; | |
| drawOverlay(); | |
| currentTexture = textures[TEX_DEFAULT]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment