// Display func for sub window 1 void renderScenesw1() { glutSetWindow(subWindow1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(x, y, z, x + lx,y + ly,z + lz, 0.0f,1.0f,0.0f); renderScene2(); // display fps in the top window frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"Lighthouse3D - FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } setOrthographicProjection(); glPushMatrix(); glLoadIdentity(); renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_12,s); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }
void renderPostProcess(FrameBufferObject* target, Shader* shader, bool clear) { if(clear) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } glEnable(GL_TEXTURE_RECTANGLE); setOrthographicProjection(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_RECTANGLE, target->getColorBuffer()); shader->bindShader(); glBegin(GL_QUADS); glTexCoord2i(0,HEIGHT); glVertex2i(0,0); glTexCoord2i(WIDTH,HEIGHT); glVertex2i(WIDTH,0); glTexCoord2i(WIDTH,0); glVertex2i(WIDTH,HEIGHT); glTexCoord2i(0,0); glVertex2i(0,HEIGHT); glEnd(); shader->unbindShader(); glBindTexture(GL_TEXTURE_RECTANGLE, 0); glDisable(GL_TEXTURE_RECTANGLE); restorePerspectiveProjection(); }
void DialogBalloon::draw(int selection) { if(textField){ textField->x=x+8-(width/2); textField->y=y-height-footerHeight+8; } if(titleTextField){ titleTextField->x=x+8-(width/2); titleTextField->y=y-height-footerHeight-headerHeight+8; } setOrthographicProjection(selection); glColor4f(red, green, blue, alpha); //Draw body background Draw2D::Rectangle(x-(width/2), y-footerHeight-height, width, height); //Draw Header background Draw2D::Rectangle(x-(width/2), y-footerHeight-headerHeight+1-height, width, headerHeight); //Create triangle point glBegin(GL_POLYGON); glVertex2f(x, y); glVertex2f(x-20, y-footerHeight); glVertex2f(x+20, y-footerHeight); glEnd(); glColor3f(255,255,255); restorePerspectiveProjection(); }
void Image2D::draw(int selection) { setOrthographicProjection(selection); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture Draw2D::Rectangle(x, y, width, height); glBindTexture(GL_TEXTURE_2D, 0); restorePerspectiveProjection(); }
void player_position (void) { char position[50]; sprintf(position,"X = %f, Y = %f, Z = %f", xpos, ypos, zpos); setOrthographicProjection(); //glDisable (GL_LIGHTING); glPushMatrix(); glLoadIdentity(); renderBitmapString(5,50,0,GLUT_BITMAP_HELVETICA_18, position); glPopMatrix(); //glEnable (GL_LIGHTING); restorePerspectiveProjection(); }
void renderDisplayStart(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( 0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); drawStart(0.0f); setOrthographicProjection(); glPushMatrix(); glLoadIdentity(); glColor3f(0.0f, 0.0f, 1.0f); renderBitmapString(315,250,1,fontBitmap,(char *)"START"); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }
void calcFPS(){ // Code to compute frames per second frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } // Code to display a string (fps) with bitmap fonts setOrthographicProjection(); glPushMatrix(); glLoadIdentity(); renderBitmapString(5,30,0,GLUT_BITMAP_TIMES_ROMAN_24,s); glPopMatrix(); restorePerspectiveProjection(); }
void fps (void) { frame++; timez = glutGet(GLUT_ELAPSED_TIME); if ((timez - timebase) > 1000) { sprintf(s,"FPS:%4.2f", frame*1000.0/(timez-timebase)); timebase = timez; frame = 0; } setOrthographicProjection(); // glDisable (GL_LIGHTING); glPushMatrix(); glLoadIdentity(); renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_18,s); glPopMatrix(); //glEnable (GL_LIGHTING); restorePerspectiveProjection(); }
void drawStart(float zz) { glColor3f(0.9f, 0.9f, 0.9f); glBegin(GL_POLYGON); glVertex3f(0.0f, -1.0f, zz); glVertex3f(1.0f, -1.0f, zz); glVertex3f(1.5f, -0.5f, zz); glVertex3f(1.5f, 0.5f, zz); glVertex3f(1.0f, 1.0f, zz); glVertex3f(-1.0f, 1.0f, zz); glVertex3f(-1.5f, 0.5f, zz); glVertex3f(-1.5f, -0.5f, zz); glVertex3f(-1.0f, -1.0f, zz); glVertex3f(0.0f, -1.0f, zz); glEnd(); setOrthographicProjection(); renderBitmapString(-1.0f, 0.0f, 0.5f,fontBitmap,(char *)"START"); restorePerspectiveProjection(); }
/* http://www.lighthouse3d.com/tutorials/glut-tutorial/bitmap-fonts-and-orthogonal-projections/ */ static void drawInfo() { char buf[1024]; setOrthographicProjection(); glPushMatrix(); glLoadIdentity(); glColor3f(1.0f, 1.0f, 1.0f); glRasterPos2i(20, 20); snprintf(buf, sizeof(buf), "Time: %4.3f / %4.3f Gyr (%4.3f %%)\n", scene->info.currentTime, scene->info.timeEvolve, 100.0f * scene->info.currentTime / scene->info.timeEvolve ); nbody_glutBitmapStringHelvetica(buf); glPopMatrix(); restorePerspectiveProjection(); }
void LensFlareSunDemo::renderHud() { setOrthographicProjection(); restorePerspectiveProjection(); }
void LensFlareSunDemo::renderSky() { skyShader.bindShader(); renderSkyPlane(&camera); skyShader.unbindShader(); setOrthographicProjection(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); renderSun(-64.0f,-64.0f); GLfloat center_x = WIDTH * 0.5f; GLfloat center_y = HEIGHT * 0.5f; GLfloat screenPos_x = -64.0f; GLfloat screenPos_y = -64.0f; // screenPos is the onscreen position of the sun // mind that the pixel coordinates have been scaled // to fit our viewport GLfloat dx = center_x - screenPos_x; GLfloat dy = center_y - screenPos_y; GLfloat len = sqrt(dx * dx + dy * dy); // normalize the vector GLfloat vx = dx / len; GLfloat vy = dy / len; // choose a spacing between elements dx = vx * len * 0.4f; dy = vy * len * 0.4f; // note that we already are in 2D (orthogonal) // mode here glPushMatrix(); glTranslatef(screenPos_x, screenPos_y, 0); // travel down the line and draw the elements int numElements = 4; glBindTexture(GL_TEXTURE_2D,streaks4.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,halo3.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,bigGlow3.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,hardGlow2.texture); glTranslatef(dx, dy, 0); renderFlare(); glPopMatrix(); glDisable(GL_BLEND); restorePerspectiveProjection(); }
void renderScene(void) { //Set up Viewport 1 scene // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); glScissor(0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9); glEnable(GL_SCISSOR_TEST); glClearDepth(1.0); glClearColor(0.49f, 0.75f, 0.93f, 1.0f); // Set the viewport to be the entire window glViewport (0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9); // Set the correct perspective. if (viewMode == PERSPECTIVE) gluPerspective(45.0f*zoom, ratio, 1.0f, 1000.0f); else if (viewMode == ORTHOGRAPHIC) glOrtho((-windowWidth/50)*zoom, (windowWidth/50)*zoom, (-windowHeight/50)*zoom, (windowHeight/50)*zoom, 1.0f, 1000); // Get Back to the Modelview glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Decide if wire frame or shaded if (polygonMode == WIREFRAME) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else if (polygonMode == SHADED) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLoadIdentity(); moveCamera(); lx = (sin(heliRot+PI)); lz = (cos(heliRot+PI)); float camX = curX + lx * 10.0f; float camZ = curZ + lz * 10.0f; //Set camera if (viewPerson == THIRD) { gluLookAt(eyeX+curX, eyeY, eyeZ+curZ, curX, 0.0f, curZ, upX, upY, upZ); } else if (viewPerson == FIRST) { gluLookAt(camX, 1.5f, camZ, camX+lx, 1.5f, camZ+lz, 0.0f, 1.0f, 0.0f); } glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); // smooth out lighting glEnable(GL_NORMALIZE); // normalize lighting GLfloat mat_specular[] = {0.3, 0.3, 0.3, 1.0}; GLfloat mat_shininess[] = { 10.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); if (lightingEnabled) { glEnable(GL_LIGHTING); if (sunlight) { setSunlight(); } else { glDisable(GL_LIGHT0); } if (thirdPersonLight) { setThirdPersonLight(); } else { glDisable(GL_LIGHT3); } } else { glDisable(GL_LIGHTING); } glPushMatrix(); glTranslatef(0.0f, -10, 0.0f); drawGround(250, 100); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, -9.9, 0.0f); drawTrack(100.0, 100.0); glPopMatrix(); glPushMatrix(); moveHelicopter(); glRotatef(heliRot/PI*180, 0.0f, 1.0f, 0.0f); drawHelicopter(); if (lightingEnabled) { if (circleLight) { moveLight(); setCircularLight(); } else { glDisable(GL_LIGHT2); } } glPopMatrix(); //Set up Viewport 2 scene // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); glScissor(0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1); glEnable(GL_SCISSOR_TEST); glClearDepth(1.0); glClearColor(1, 1, 1, 1); // Set the viewport to be the entire window glViewport (0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1); // Set the correct perspective. // Get Back to the Modelview glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } glColor3f(0.0f,0.0f,0.0f); glPushMatrix(); glLoadIdentity(); setOrthographicProjection(); glTranslatef(100.0f, 150, 0.0f); renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_18,s); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }
void renderScene(void) { if (deltaMove) computePos(deltaMove); //if (deltaAngle) // computeDir(deltaAngle); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Reset Transformations glLoadIdentity(); //Set the camera gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); //glRotatef(angle, 0.0, 0.0, 1.0); //Draw GROUND glColor3f(0.9f,0.9f,0.9f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); //angle+=0.10f; //Draw 36 Snowmen char number[3]; for(int i=-3;i<3;i++) { for(int j=-3;j<3;j++) { glPushMatrix(); glTranslatef(i*10.0,0,j*10.0); snowman(); sprintf(number,"%d",(i+3)*6+(j+3)); renderStrokeFontString(0.0f, 0.5f, 0.0f, (void *)font ,number); glPopMatrix(); } } // Code to compute frames per second frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"Lighthouse3D - FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } // Code to display a string (fps) with bitmap fonts setOrthographicProjection(); void *font= GLUT_BITMAP_8_BY_13; glPushMatrix(); glLoadIdentity(); renderBitmapString(30,15,0,font,(char *)"GLUT Tutorial @ Lighthouse3D"); renderBitmapString(30,30,0,font,s); renderBitmapString(30,45,0,font,(char *)"F1 - Game Mode 640x480 32 bits"); renderBitmapString(30,60,0,font,(char *)"F2 - Game Mode 800x600 32 bits"); renderBitmapString(30,75,0,font,(char *)"F3 - Game Mode 1024x768 32 bits"); renderBitmapString(30,90,0,font,(char *)"F4 - Game Mode 1280x1024 32 bits"); renderBitmapString(30,105,0,font,(char *)"F5 - Game Mode 1920x1200 32 bits"); renderBitmapString(30,120,0,font,(char *)"F6 - Window Mode"); renderBitmapString(30,135,0,font,(char *)"Esc - Quit"); renderBitmapString(30,150,0,font,currentMode); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }