/////////////////////////////////////////////////////////////////////////////// // Reset flags as appropriate in response to menu selections void ProcessMenu(int value) { // For historgram, do not change render mode, just set // histogram flag to true if(value == 6) // Histogram { bHistogram = GL_TRUE; glutPostRedisplay(); return; } if(value == 0) // Save image gltWriteTGA("ScreenShot.tga"); else // Change render mode index to match menu entry index iRenderMode = value; // Trigger Redraw glutPostRedisplay(); }
void renderScene() { //Colours: static GLfloat vDarkRed[] = {0.0f, 0.396f, 0.702f, 1.0f}; static GLfloat vDarkGrey[] = {0.2f, 0.2f, 0.2f, 1.0f}; static CStopWatch inputTimer; //Clear buffers glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //Beginning push: modelViewStack.PushMatrix(); //Camera matrix: M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); modelViewStack.Rotate(-15.0f, 1.0f, 0.0f, 0.0f); if (screenshot) { cameraFrame.SetForwardVector(0, 0, -1); cameraFrame.SetUpVector(0, 1, 0); cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); } //Light source: static M3DVector4f vAmbient = {0.1f, 0.1f, 0.1f, 1.0f}; static M3DVector4f vLightPos = {4.0f, -6.5f, 10.0f, 1.0f}; static M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); //Draw floor and grid: glEnable(GL_MULTISAMPLE); cRoom.draw(shaderManager, tPipeline, modelViewStack); // Highlight grid hlGrid.draw(shaderManager, tPipeline, modelViewStack); //Draw desks: stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient); //Draw polygon version of desks glDisable(GL_MULTISAMPLE); //Disable multisampling (to use AA) glEnable(GL_BLEND); //Enable blending glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonOffset(-1.0f, -1.0f); glEnable(GL_POLYGON_OFFSET_LINE); //Render wireframe in front of polygon glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //Wireframe mode glEnable(GL_LINE_SMOOTH); //Enable AA stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient, vDarkGrey); //Draw wireframe version of desks //Reset stuff as they were before: glDisable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); //End cam push: modelViewStack.PopMatrix(); //End pop: modelViewStack.PopMatrix(); if (!screenshot) { newDeskButton.draw(W_WIDTH, W_HEIGHT); removeDeskButton.draw(W_WIDTH, W_HEIGHT); exportButton.draw(W_WIDTH, W_HEIGHT); } glutSwapBuffers(); if (screenshot) { char name[38]; sprintf(name, "Exports/screenshot%d.tga", expCounter); gltWriteTGA(name); counterSaver(); modelViewStack.PopMatrix(); screenshot = false; } glutPostRedisplay(); handleInput(inputTimer); }
/* gestisce i tasti carattere */ void keyHandler(GLubyte key, GLint x, GLint y){ static int sCount=0; if(key== 'q'){ fprintf(stderr, "Exit\n"); programData.exit = 1; }else{ if(key == 'p'){ /* menu */ programData.menu = !programData.menu; }else{ if(key == 'm'){ /* multisampling */ programData.multisample = !programData.multisample; if(programData.multisample){ fprintf(stderr, "MULTISAMPING ON\n"); glEnable(GL_MULTISAMPLE); } else{ fprintf(stderr, "MULTISAMPING OFF\n"); glDisable(GL_MULTISAMPLE); } }else{ if(key == 'f'){ /* nebbia */ programData.fog= !programData.fog; if(programData.fog){ fprintf(stderr, "FOG ON\n"); fog(1); } else{ fprintf(stderr, "FOG OFF\n"); fog(0); } }else{ if(key == 'n'){ /* nuova partita */ programData.gameStatus = 1; programData.menu = 0; programData.points= 0; /* Inizializzo la posizione della telecamera */ worldData.angleX = 0.0f; worldData.angleY = 0.0f; worldData.angleMX = 0.0f; worldData.angleMY = 0.0f; worldData.nextAngleX = 0.0f; worldData.nextAngleY = 0.0f; worldData.nextAngleMX = 0.0f; worldData.nextAngleMY = 0.0f; /* Inizializzo il verme */ initializeWorm(0.0f, 0.0f, 83.5f, 0); srand(time(NULL)); /* Inizializzo la palla */ initializeBall(); /* Inizializzo i dati utilizzati per la telecamera */ worldData.kup = 0; worldData.kdown = 0; worldData.kleft = 0; worldData.kright = 0; worldData.xStatus = 0; worldData.yStatus = 0; worldData.nextXstatus = 0; worldData.nextYstatus = 0; programData.velocity = VELOCITY; programData.timeFrame = 1250/programData.velocity; programData.velAngolare = programData.velocity*0.2; programData.timerender = programData.time; programData.timebase = programData.time; programData.frame = 0; }else{ if(key == 's'){/* screenshot */ char sname[20]; sprintf(sname, "screenshot%d.tga",sCount); gltWriteTGA(sname); sCount++; } } } } } } }