static void drawSample(int x, int y, int w, int h, struct formatInfo *format, struct envModeInfo *envMode) { glViewport(x, y, w, h); glScissor(x, y, w, h); glClearColor(0.1, 0.1, 0.1, 1.0); glClear(GL_COLOR_BUFFER_BIT); begin2D(w, h); drawString(format->name, 10, h - 15, labelInfoColor); drawString(envMode->name, 10, 5, labelInfoColor); end2D(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envMode->mode); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envColors[envColor]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); loadTexture(textureWidth, textureHeight, format); if (drawBackground) { drawCheck(15, 15, lightCheck, darkCheck); } if (drawBlended) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } if (drawSmooth) { glShadeModel(GL_SMOOTH); } if (drawTextured) { glEnable(GL_TEXTURE_2D); } glBegin(GL_QUADS); glColor4f(1.0, 0.0, 0.0, 1.0); glTexCoord2f(0.0, 0.0); glVertex2f(-0.8, -0.8); glColor4f(0.0, 1.0, 0.0, 1.0); glTexCoord2f(1.0, 0.0); glVertex2f(0.8, -0.8); glColor4f(0.0, 0.0, 1.0, 1.0); glTexCoord2f(1.0, 1.0); glVertex2f(0.8, 0.8); glColor4f(1.0, 1.0, 1.0, 1.0); glTexCoord2f(0.0, 1.0); glVertex2f(-0.8, 0.8); glEnd(); glDisable(GL_BLEND); glShadeModel(GL_FLAT); glDisable(GL_TEXTURE_2D); if (displayLevelInfo) { GLint width, height, border, components; #if GL_EXT_texture GLint redSize, greenSize, blueSize, alphaSize; GLint luminanceSize, intensitySize; #endif char buf[255]; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &components); #if GL_EXT_texture glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE_EXT, &redSize); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE_EXT, &greenSize); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE_EXT, &blueSize); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE_EXT, &alphaSize); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE_EXT, &luminanceSize); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE_EXT, &intensitySize); #endif begin2D(w, h); sprintf(buf, "dimensions: %d x %d", width, height); drawStringOutline(buf, 15, h / 2 + 20, labelLevelColor0, labelLevelColor1); sprintf(buf, "border: %d", border); drawStringOutline(buf, 15, h / 2 + 10, labelLevelColor0, labelLevelColor1); sprintf(buf, "components: 0x%04X", components); drawStringOutline(buf, 15, h / 2, labelLevelColor0, labelLevelColor1); sprintf(buf, "sizes:"); drawStringOutline(buf, 15, h / 2 - 10, labelLevelColor0, labelLevelColor1); #if GL_EXT_texture sprintf(buf, " %d/%d/%d/%d/%d/%d", redSize, greenSize, blueSize, alphaSize, luminanceSize, intensitySize); drawStringOutline(buf, 15, h / 2 - 20, labelLevelColor0, labelLevelColor1); #endif end2D(); } }
void C_API Program::Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glInitNames(); if (m_ShowText) { begin2D(m_window_width, m_window_height); glColor3f(1.0f, 1.0f, 1.0f); glPrintf(10, m_window_height-20, "Object Loaded In %f Seconds", m_LoadedObj.fLoadTimeInSecs); glPrintf(10, m_window_height-40, "Vertices: %u", m_LoadedObj.nVertexCount); glPrintf(10, m_window_height-60, "Normals: %u", m_LoadedObj.nNormalCount); glPrintf(10, m_window_height-80, "UVs: %u", m_LoadedObj.nUVCount); glPrintf(10, 20, "FPS: %i", calcFPS()); end2D(); } if (m_LoadedObj.pMesh != NULL) { glPushMatrix(); glTranslatef(0.0f, 0.0f, m_Zoom); glRotatef(-(m_AngleY), 1.0f, 0.0f, 0.0f); glRotatef(-(m_AngleX), 0.0f, 1.0f, 0.0f); Mesh::RenderMode renderMode; if (m_Wireframe) { renderMode = Mesh::Wireframe; glLineWidth(1.0f); // Wireframe Line Color: glColor3f(0.6f, 0.6f, 0.77f); } else { renderMode = Mesh::Solid; glLineWidth(2.0f); } // Render Everything: if (m_LoadedObj.nDrawByGroupID == -1) { // First Pass, Normal Rendering: if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } m_LoadedObj.pMesh->SetRenderMode(renderMode); Mesh::GroupMap::const_iterator GroupIndex = m_LoadedObj.pMesh->Groups().begin(); Mesh::GroupMap::const_iterator LastGroup = m_LoadedObj.pMesh->Groups().end(); GLuint name = 0; while (GroupIndex != LastGroup) { glPushName(name); m_LoadedObj.pMesh->Render(GroupIndex); glPopName(); ++name; ++GroupIndex; } if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); } // Second Pass, Draw Group Outline: if (m_LoadedObj.nSelectedGroup != -1) { glColor3f(0.2f, 0.8f, 0.35f); // Give It A Cool Maya Style Outline Color. m_LoadedObj.pMesh->SetRenderMode(Mesh::Wireframe); m_LoadedObj.pMesh->Render(m_LoadedObj.pMesh->Groups().find(m_vMeshGroups[m_LoadedObj.nSelectedGroup])); } } else // Render The Selected Group Only: { if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } m_LoadedObj.pMesh->SetRenderMode(renderMode); m_LoadedObj.pMesh->Render(m_LoadedObj.pMesh->Groups().find(m_vMeshGroups[m_LoadedObj.nDrawByGroupID])); if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); } } glPopMatrix(); } glFlush(); glutSwapBuffers(); }
static void drawSample( int x, int y, int w, int h, int texgenenabled, int coordnr ) { char buf[255]; glViewport( x, y, w, h ); glScissor( x, y, w, h ); glClearColor( 0.1, 0.1, 0.1, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); begin2D( w, h ); if (texgenenabled == 2) { sprintf( buf, "TexCoord%df", coordnr); drawString( buf, 10, h - 15, labelInfoColor ); sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S" : "S/T"); drawString( buf, 10, 5, labelInfoColor ); } else if (texgenenabled == 0) { sprintf( buf, "TexCoord%df", coordnr); drawString( buf, 10, h - 15, labelInfoColor ); drawString( "no texgen", 10, 5, labelInfoColor ); } else if (texgenenabled == 1) { drawString( "no TexCoord", 10, h - 15, labelInfoColor ); sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S/T" : (coordnr == 3 ? "S/T/R" : "S/T/R/Q")); drawString( buf, 10, 5, labelInfoColor ); } end2D(); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); loadTexture( textureWidth, textureHeight ); if ( drawTextured ) { glEnable( GL_TEXTURE_2D ); } glDisable( GL_TEXTURE_GEN_S ); glDisable( GL_TEXTURE_GEN_T ); glDisable( GL_TEXTURE_GEN_R ); glDisable( GL_TEXTURE_GEN_Q ); glMatrixMode( GL_TEXTURE ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); switch (coordnr) { case 2: switch (texgenenabled) { case 0: glBegin( GL_QUADS ); glTexCoord2f( 0.0, 0.0 ); glVertex2f( -0.8, -0.8 ); glTexCoord2f( 1.0, 0.0 ); glVertex2f( 0.8, -0.8 ); glTexCoord2f( 1.0, 1.0 ); glVertex2f( 0.8, 0.8 ); glTexCoord2f( 0.0, 1.0 ); glVertex2f( -0.8, 0.8 ); glEnd(); break; case 1: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS3); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT3); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); /* Issue a texcoord here to be sure Q isn't left over from a * previous sample. */ glTexCoord1f( 0.0 ); glBegin( GL_QUADS ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 2: /* make sure that texgen T and non-texgen S coordinate are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS1); glTexGenfv(GL_T, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glBegin( GL_QUADS ); /* use z coordinate to get correct texgen values... */ glTexCoord2f( 0.0, 0.0 ); glVertex3f( -0.8, -0.8, 0.8 ); glTexCoord2f( 0.0, 0.0 ); glVertex3f( 0.8, -0.8, 0.2 ); glTexCoord2f( 0.0, 1.0 ); glVertex3f( 0.8, 0.8, 0.2 ); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -0.8, 0.8, 0.8 ); glEnd(); break; } break; case 3: glMatrixMode( GL_TEXTURE ); glLoadMatrixf( texmat_swap_rq ); glMatrixMode( GL_MODELVIEW ); glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); switch (texgenenabled) { case 0: glBegin( GL_QUADS ); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0 ); glTexCoord3f( 0.5, 0.0, 0.5 ); glVertex2f( 1.0, 0.0 ); glTexCoord3f( 0.5, 0.5, 0.5 ); glVertex2f( 1.0, 1.0 ); glTexCoord3f( 0.0, 0.5, 0.5 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 1: glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glTexCoord1f( 0.0 ); /* to make sure Q is 1.0 */ glBegin( GL_QUADS ); glVertex3f( 0.0, 0.0, 0.5 ); glVertex3f( 1.0, 0.0, 0.5 ); glVertex3f( 1.0, 1.0, 0.5 ); glVertex3f( 0.0, 1.0, 0.5 ); glEnd(); break; case 2: /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glBegin( GL_QUADS ); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 1.0, 0.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 1.0, 1.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 1.0); glEnd(); break; } break; case 4: switch (texgenenabled) { case 0: glBegin( GL_QUADS ); /* don't need r coordinate but still setting it I'm mean */ glTexCoord4f( 0.0, 0.0, 0.0, 0.5 ); glVertex2f( -0.8, -0.8 ); glTexCoord4f( 0.5, 0.0, 0.2, 0.5 ); glVertex2f( 0.8, -0.8 ); glTexCoord4f( 0.5, 0.5, 0.5, 0.5 ); glVertex2f( 0.8, 0.8 ); glTexCoord4f( 0.0, 0.5, 0.5, 0.5 ); glVertex2f( -0.8, 0.8 ); glEnd(); break; case 1: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR); glTexGenfv(GL_Q, GL_OBJECT_PLANE, ObjPlaneQ); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glEnable( GL_TEXTURE_GEN_Q ); glBegin( GL_QUADS ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 2: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glBegin( GL_QUADS ); glTexCoord4f( 0.0, 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0 ); glTexCoord4f( 0.0, 0.0, 0.2, 0.5 ); glVertex2f( 1.0, 0.0 ); glTexCoord4f( 0.0, 0.0, 0.5, 0.5 ); glVertex2f( 1.0, 1.0 ); glTexCoord4f( 0.0, 0.0, 0.75, 0.5 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; } break; } glPopMatrix(); glDisable( GL_TEXTURE_2D ); }