void renderScene(void) { if (deltaMove || lstrafe || rstrafe) computePos(deltaMove); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(102.0/255.0, 204.0/255.0, 1.0f, 1.0f); glLoadIdentity(); gluLookAt( x, 1.0f, z, x+lx, 1.0+ly, z+lz, 0.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.65f, 0.0f); 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(); int i,j; //Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(29.6,0,30); drawDoorZ(); glPopMatrix(); //Door attached wall r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(33,0,30.6); drawWallX(10); glPopMatrix(); //Door attached wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallZ(3); glPopMatrix(); //Living room wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallX(-5); glPopMatrix(); //Long living room wall glPushMatrix(); glTranslatef(26.6,0,25); drawWallZ(-30); glPopMatrix(); //Balcony to hall living room connector glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(15); glPopMatrix(); //Balcony parapet r = 0.0, g = 0.0, b = 0.0; glPushMatrix(); glTranslatef(-9.6,0,25.65); drawParapetX(14.2); glPopMatrix(); r = 0.9, g = 0.9, b = 0.9; //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,25); drawWallZ(-6); glPopMatrix(); //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(-6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,25); drawWallX(6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,34); drawWallX(6); glPopMatrix(); //Shoebox wall glPushMatrix(); glTranslatef(33,0,40); drawWallZ(-6); glPopMatrix(); //Hall wall to bathroom glPushMatrix(); glTranslatef(27,0,40); drawWallX(15); glPopMatrix(); //Hall wall glPushMatrix(); glTranslatef(11.6,0,40); drawWallX(25); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27,0,55); drawDoorX(); glPopMatrix(); //Bedroom bathroom separator r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27,0,59); drawWallX(1); glPopMatrix(); //Bathroom walls r = 0.0, g = 0.0, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,59); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(27.6,0,49); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(-10); glPopMatrix(); //Bedroom walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,59.6); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallX(-4.8); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27.6,0,60.2); drawDoorX(); glPopMatrix(); //Bedroom kitchen separator r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(-5); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,69); drawWallX(15); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,84); drawWallZ(-7); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(15.6,0,84); drawWallX(-15); glPopMatrix(); //Kitchen bedroom separator glPushMatrix(); glTranslatef(15.6,0,69); drawWallZ(-2); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,69); drawWallX(15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,84); drawWallZ(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,84); drawWallX(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,69); drawWallZ(12); glPopMatrix(); //Bedroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(9.6,0,69); drawDoorZ(); glPopMatrix(); //Bathroom 2 walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(5.6,0,65); drawWallZ(-13); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,65); drawWallX(-6); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(19); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(9.6,0,65); drawWallZ(2); glPopMatrix(); //Bathroom 2 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(5.59,0,65); drawDoorZ(); glPopMatrix(); //Bedroom 3 walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(-6); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,59); drawWallX(25); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,84); drawWallZ(15); glPopMatrix(); //Bedroom 3 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(-2.6,0,65); drawDoorX(); glPopMatrix(); glPushMatrix(); glTranslatef(-30,0,-30); watersim(); glPopMatrix(); glutSwapBuffers(); }
void display(){ glClearColor(0.17f, 0.4f, 0.6f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(recalcLabyrinth){ int level = dataBuffer->getLevels() - 1; dataBuffer->setRenderTarget(level); GLenum ca = GL_COLOR_ATTACHMENT0; glDrawBuffers(1, &ca); glClearColor(1,0,1,0); glClear(GL_COLOR_BUFFER_BIT); ca = GL_COLOR_ATTACHMENT1; glDrawBuffers(1, &ca); glClearColor(0.5,0.5,0.5,0.5); glClear(GL_COLOR_BUFFER_BIT); float scale = noiseStart; for(level = level - 1; level >= 0; level--){ dataBuffer->setRenderTarget(level); generateShader->enable(); generateShader->bindUniformInt("level", level); generateShader->bindUniformFloat("noiseScale", scale); generateShader->bindUniformFloat("noiseSeed", noiseSeed * 16.0); generateShader->bindUniformTexture("inputTex1", dataBuffer->getColorBuffer(0),0); generateShader->bindUniformTexture("inputTex2", dataBuffer->getColorBuffer(1),1); generateShader->bindUniformTexture("noiseTex", noiseTexture->getTextureHandle(),2); fullscreenQuad->render(generateShader); generateShader->disable(); scale *= noiseScale; } dataBuffer->disableRenderTarget(); recalcLabyrinth = false; startPointChanged = true; } if(startPointChanged) { endpointChanged = true; shortestPath->setRenderTarget(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); searchShader->enable(); searchShader->bindUniformTexture("inputTex1", dataBuffer->getColorBuffer(0), 0); searchShader->bindUniformTexture("inputTex2", shortestPath->getColorBuffer(0), 1); recursion(startX, startY, 0, 5); searchShader->disable(); shortestPath->disableRenderTarget(); startPointChanged = false; } if(endpointChanged) { visualizeTex->setRenderTarget(); visualizeShader->enable(); visualizeShader->bindUniformTexture("inputTex", dataBuffer->getColorBuffer(0),0); fullscreenQuad->render(visualizeShader); visualizeShader->disable(); walkPathShader->enable(); walkPathShader->bindUniformTexture("inputTex1", shortestPath->getColorBuffer(0), 0); recursion(endX, endY, 0, 5); walkPathShader->disable(); glBegin(GL_POINTS); glColor3f(0,0,1); glVertex3f((float)(startX * 2 + 1) / (float)(2 * labyrinthSize) * 2.0f - 1.0f, (float)(startY * 2 + 1) / (float)(2 * labyrinthSize) * 2.0f - 1.0f, 0); glColor3f(0,1,0); glVertex3f((float)(endX * 2 + 1) / (float)(2 * labyrinthSize) * 2.0f - 1.0f, (float)(endY * 2 + 1) / (float)(2 * labyrinthSize) * 2.0f - 1.0f, 0); glEnd(); visualizeTex->disableRenderTarget(); endpointChanged = false; } glViewport(0,0,windowWidth, windowHeight); simpleShader->enable(); simpleShader->bindUniformTexture("inputTex", visualizeTex->getColorBuffer(0),0); fullscreenQuad->render(simpleShader); simpleShader->disable(); glutSwapBuffers(); }
void display(void) { static char s[256], t[32]; static char* p; static int frames = 0; glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(pan_x, pan_y, 0.0); gltbMatrix(); if(!start) { #if 0 // glmDraw() performance test if (material_mode == 0) { if (facet_normal) glmDraw(model, GLM_FLAT); else glmDraw(model, GLM_SMOOTH); } else if (material_mode == 1) { if (facet_normal) glmDraw(model, GLM_FLAT | GLM_COLOR); else glmDraw(model, GLM_SMOOTH | GLM_COLOR); } else if (material_mode == 2) { if (facet_normal) glmDraw(model, GLM_FLAT | GLM_MATERIAL); else glmDraw(model, GLM_SMOOTH | GLM_MATERIAL); } #else glCallList(model_list); #endif glDisable(GL_LIGHTING); if (bounding_box) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_CULL_FACE); glColor4f(1.0, 0.0, 0.0, 0.25); glutSolidCube(2.0); glDisable(GL_BLEND); } } else { //glDisable(GL_LIGHTING); newDrawMechanism(); glEnable(GL_LIGHTING); } glPopMatrix(); if (stats) { /* XXX - this could be done a _whole lot_ faster... */ int height = glutGet(GLUT_WINDOW_HEIGHT); glColor3ub(0, 0, 0); sprintf(s, "%s\n%d vertices\n%d triangles\n%d normals\n" "%d texcoords\n%d groups\n%d materials", model->pathname, model->numvertices, model->numtriangles, model->numnormals, model->numtexcoords, model->numgroups, model->nummaterials); shadowtext(5, height-(5+18*1), s); } /* spit out frame rate. */ frames++; if (frames > NUM_FRAMES) { sprintf(t, "%g fps", frames/elapsed()); frames = 0; } if (performance) { shadowtext(5, 5, t); } glutSwapBuffers(); glEnable(GL_LIGHTING); }
static void render(void) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glutSwapBuffers(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.0f); if (1) { if (textureContainsData) { glDeleteTextures(1, &g_TextureArray[g_ID]); } glGenTextures(1, &g_TextureArray[g_ID]); glBindTexture(GL_TEXTURE_2D, g_TextureArray[g_ID]); //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_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, frame->w, frame->h, 0, // texture_format, GL_UNSIGNED_BYTE, frame->pixels); if (0) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_TextureWidth, g_TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_data); } else { //FIXME: multi thread here, screen will be null (not timer thread) pthread_mutex_lock(screen_mutex); if (screen != NULL) { SDLMOD_LockSurface(screen); //dumpBMPRaw("image1_out.bmp", screen->pixels, screen->w, screen->h); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen->w, screen->h, 0, GL_RGB, GL_UNSIGNED_BYTE, screen->pixels); SDLMOD_UnlockSurface(screen); } pthread_mutex_unlock(screen_mutex); } textureContainsData = 1; } else { glBindTexture(GL_TEXTURE_2D, g_TextureArray[0]); } glScalef(1.0f, -1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); glEnd(); glutSwapBuffers(); }
//----------------------------------------------------------------// static void _onPaint () { AKURender (); glutSwapBuffers (); }
void DrawScene(void) { /* clear the draw buffer */ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // clear the rasterization framebuffer memset(framebuffer, 0, 3*framebuffer_width*framebuffer_height); if (scene == 1) DrawTriangles(); else if (scene == 2) TestRasterizationSpeed(); else if (scene == 4) DrawPixels(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (scene != 9) { if (zoom) glOrtho(0, framebuffer_width, 0, framebuffer_height, -1, 1); else glOrtho(0, screen_width, 0, screen_height, -1, 1); // Draw textured quad glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, framebuffer_width, framebuffer_height, 0, GL_RGB, GL_UNSIGNED_BYTE, framebuffer); glColor3f(1, 1, 1); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(0, 0); glTexCoord2i(1, 0); glVertex2i(framebuffer_width, 0); glTexCoord2i(1, 1); glVertex2i(framebuffer_width, framebuffer_height); glTexCoord2i(0, 1); glVertex2i(0, framebuffer_height); glEnd(); } else { if (zoom) glOrtho(-0.5, framebuffer_width-0.5, -0.5, framebuffer_height-0.5, -1, 1); else glOrtho(-0.5, screen_width-0.5, -0.5, screen_height-0.5, -1, 1); DrawTrianglesOpenGL(); glDisable(GL_TEXTURE_2D); glColor3f(1, 1, 0); glBegin(GL_POINTS); glVertex2i(0, 0); glVertex2i(framebuffer_width-1, framebuffer_height-1); glEnd(); } // finally, swap the draw buffers to make the triangles appear on screen glutSwapBuffers(); }
static void redraw(void) { int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(15.0, 1.0, 0.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); glDepthMask(GL_FALSE); /* Draw the floor. */ /* glEnable(GL_TEXTURE_2D);*/ glColor3f(0.1, 0.5, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-EDGE, -0.05, -EDGE); glTexCoord2f(20.0, 0.0); glVertex3f(EDGE, -0.05, -EDGE); glTexCoord2f(20.0, 20.0); glVertex3f(EDGE, -0.05, EDGE); glTexCoord2f(0.0, 20.0); glVertex3f(-EDGE, -0.05, EDGE); glEnd(); /* Allow particles to blend with each other. */ glDepthMask(GL_TRUE); if (blend) glEnable(GL_BLEND); if (sprite) { glEnable(GL_TEXTURE_2D); #ifdef GL_ARB_point_sprite glEnable(GL_POINT_SPRITE_ARB); #endif } glColor3f(1,1,1); glBegin(GL_POINTS); for (i=0; i<numPoints; i++) { /* Draw alive particles. */ if (colorList[i] != DEAD) { if (!sprite) glColor4fv(colorSet[colorList[i]]); glVertex3fv(pointList[i]); } } glEnd(); glDisable(GL_TEXTURE_2D); #ifdef GL_ARB_point_sprite glDisable(GL_POINT_SPRITE_ARB); #endif glDisable(GL_BLEND); glPopMatrix(); glutSwapBuffers(); }
static void post_display ( void ) { glutSwapBuffers (); }
// __________Função callback chamada para fazer o desenho_______________________ void Desenha(void) { int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for(i=0;i<5;i++){ if (flagdesenhocubo[i]!=0){ //(linha nova) glPushMatrix(); transfcubo[i].red = red; transfcubo[i].green = green; transfcubo[i].blue = blue; if (qualcubo == i) glColor3f(1.0, 0.0, 0.0); //else glColor3f(0.0, 1.0, 0.0); else glColor3f(transfcubo[i].red, transfcubo[i].green, transfcubo[i].blue); glTranslatef(transfcubo[i].transX, transfcubo[i].transY, transfcubo[i].transZ); glScalef(transfcubo[i].scalX, transfcubo[i].scalY, transfcubo[i].scalZ); glutSolidCube(30); glPushMatrix(); glRotatef (-90, 1.0, 0.0, 0.0); glutSolidCone(17.0, 50.0, 20, 10); glPopMatrix(); glPopMatrix(); } //fim flagdesenhocubo if (flagdesenhoarvore[i]!=0){ //(linha nova) glPushMatrix(); transfarvore[i].red = red; transfarvore[i].green = green; transfarvore[i].blue = blue; if (qualarvore == i) glColor3f(1.0, 0.0, 0.0); //else glColor3f(0.0, 1.0, 0.0); else glColor3f(transfarvore[i].red, transfarvore[i].green, transfarvore[i].blue); glTranslatef(transfarvore[i].transX, transfarvore[i].transY, transfarvore[i].transZ); glScalef(transfarvore[i].scalX, transfarvore[i].scalY, transfarvore[i].scalZ); glPushMatrix(); teste=gluNewQuadric(); glRotatef (-90, 1.0, 0.0, 0.0); gluCylinder(teste,5,5,45,80,80); glPopMatrix(); glPushMatrix(); glTranslatef(5,35,0); glutSolidSphere(9, 50, 50); glPopMatrix(); glPushMatrix(); glTranslatef(-5,35,0); glutSolidSphere(9, 50, 50); glPopMatrix(); glPushMatrix(); glTranslatef(0,40,0); glutSolidSphere(9, 50, 50); glPopMatrix(); glPushMatrix(); glTranslatef(0,30,0); glutSolidSphere(9, 50, 50); glPopMatrix(); glPopMatrix(); } //fim flagdesenhoarvore if (flagdesenhonuvem[i]!=0){ //(linha nova) glPushMatrix(); transfnuvem[i].red = red; transfnuvem[i].green = green; transfnuvem[i].blue = blue; if (qualnuvem == i) glColor3f(1.0, 0.0, 0.0); //else glColor3f(0.0, 1.0, 0.0); else glColor3f(transfnuvem[i].red, transfnuvem[i].green, transfnuvem[i].blue); glTranslatef(transfnuvem[i].transX, transfnuvem[i].transY, transfnuvem[i].transZ); glScalef(transfnuvem[i].scalX, transfnuvem[i].scalY, transfnuvem[i].scalZ); glutSolidCube(5); glPushMatrix(); glRotatef (-45, 0.0, 0.0, 1.0); glutSolidCube(5); glPopMatrix(); glPopMatrix(); } //fim flagdesenhonuvem if (flagdesenhocopo[i]!=0){ //(linha nova) glPushMatrix(); transfcopo[i].red = red; transfcopo[i].green = green; transfcopo[i].blue = blue; if (qualcopo == i) glColor3f(1.0, 0.0, 0.0); //else glColor3f(0.0, 1.0, 0.0); else glColor3f(transfcopo[i].red, transfcopo[i].green, transfcopo[i].blue); glTranslatef(transfcopo[i].transX, transfcopo[i].transY, transfcopo[i].transZ); glScalef(transfcopo[i].scalX, transfcopo[i].scalY, transfcopo[i].scalZ); glPushMatrix(); glRotatef (-90, 1.0, 0.0, 0.0); glutSolidCone(17.0, 50.0, 20, 10); glPopMatrix(); glPushMatrix(); glRotatef (-90, 1.0, 0.0, 0.0); glRotatef (-180, 0.0, 1.0, 0.0); glTranslatef(0,0,-70); glutSolidCone(17.0, 50.0, 20, 10); glPopMatrix(); glPopMatrix(); } //fim flagdesenhonuvem } // fim for glutSwapBuffers(); // Executa os comandos OpenGL }
void renderScene(void) { glViewport (0, 0, width, height ); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho( m_Ortho[0], m_Ortho[1], m_Ortho[2], m_Ortho[3], m_Ortho[4], m_Ortho[5] ); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(test_mode == 1) { glPointSize(5.0f); glColor4f(0.0,0.0,1.0,1.0 ); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, vboVertex); glVertexPointer(3,GL_FLOAT,0,0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboList); if(test_type ==1) { if(point_type == 2) { glEnable( GL_POINT_SMOOTH ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glPointSize( 6.0 ); } glDrawElements(GL_POINTS, number_elements, GL_UNSIGNED_INT, NULL); } else if(test_type ==2) { if(edge_type == 1) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); } glDrawElements(GL_LINES, number_elements*2, GL_UNSIGNED_INT, NULL); } else if(test_type ==3) { if(triangle_type == 1) { glPolygonMode(GL_FRONT, GL_LINE); glPolygonMode(GL_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_FILL); } glDrawElements(GL_TRIANGLES, number_elements*3, GL_UNSIGNED_INT, NULL); } glDisableClientState(GL_VERTEX_ARRAY); } else if(test_mode ==2) { if(test_type == 1) glCallList(DLpoint); else if(test_type == 2) glCallList(DLedge); else if(test_type == 3) glCallList(DLtriangle); } CalcFPS(); glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { GLint i; // Looping variable GLint iViewport[4]; // Viewport GLint iLargest; // Largest histogram value static GLubyte invertTable[256][3];// Inverted color table // Do a black and white scaling static GLfloat lumMat[16] = { 0.30f, 0.30f, 0.30f, 0.0f, 0.59f, 0.59f, 0.59f, 0.0f, 0.11f, 0.11f, 0.11f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; static GLfloat mSharpen[3][3] = { // Sharpen convolution kernel {0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f }, {0.0f, -1.0f, 0.0f }}; static GLfloat mEmboss[3][3] = { // Emboss convolution kernel { 2.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }}; static GLint histoGram[256]; // Storeage for histogram statistics // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Current Raster Position always at bottom left hand corner of window glRasterPos2i(0, 0); glGetIntegerv(GL_VIEWPORT, iViewport); glPixelZoom((GLfloat) iViewport[2] / (GLfloat)iWidth, (GLfloat) iViewport[3] / (GLfloat)iHeight); if(bHistogram == GL_TRUE) // Collect Historgram data { // We are collecting luminance data, use our conversion formula // instead of OpenGL's (which just adds color components together) glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); // Start collecting histogram data, 256 luminance values glHistogram(GL_HISTOGRAM, 256, GL_LUMINANCE, GL_FALSE); glEnable(GL_HISTOGRAM); } // Do image operation, depending on rendermode index switch(iRenderMode) { case 5: // Sharpen image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mSharpen); glEnable(GL_CONVOLUTION_2D); break; case 4: // Emboss image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mEmboss); glEnable(GL_CONVOLUTION_2D); glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); break; case 3: // Invert Image for(i = 0; i < 255; i++) { invertTable[i][0] = (GLubyte)(255 - i); invertTable[i][1] = (GLubyte)(255 - i); invertTable[i][2] = (GLubyte)(255 - i); } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, invertTable); glEnable(GL_COLOR_TABLE); break; case 2: // Brighten Image glMatrixMode(GL_COLOR); glScalef(1.25f, 1.25f, 1.25f); glMatrixMode(GL_MODELVIEW); break; case 1: // Just do a plain old image copy default: // This line intentially left blank break; } // Do the pixel draw glDrawPixels(iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, pImage); // Fetch and draw histogram? if(bHistogram == GL_TRUE) { // Read histogram data into buffer glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_LUMINANCE, GL_INT, histoGram); // Find largest value for scaling graph down iLargest = 0; for(i = 0; i < 255; i++) if(iLargest < histoGram[i]) iLargest = histoGram[i]; // White lines glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINE_STRIP); for(i = 0; i < 255; i++) glVertex2f((GLfloat)i, (GLfloat)histoGram[i] / (GLfloat) iLargest * 128.0f); glEnd(); bHistogram = GL_FALSE; glDisable(GL_HISTOGRAM); } // Reset everyting to default glMatrixMode(GL_COLOR); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_CONVOLUTION_2D); glDisable(GL_COLOR_TABLE); // Show our hard work... glutSwapBuffers(); }
/* * OpenGL (GLUT) calls this routine to display the scene */ void display() { // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Undo previous transformations glLoadIdentity(); // Orthogonal - set world orientation //glTranslated(pos[0],0,pos[1]); glRotatef(ph,1,0,0); glRotatef(th,0,1,0); // Flat or smooth shading glShadeModel(smooth ? GL_SMOOTH : GL_FLAT); // Add light to the scene if (light) { // Translate intensity to color vectors float Ambient[] = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0}; float Diffuse[] = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0}; float Specular[] = {0.01*specular,0.01*specular,0.01*specular,1.0}; // Light position float Position[] = {distance*Cos(zh),ylight,distance*Sin(zh),1.0}; // Draw light position as ball (still no lighting here) glColor3f(1,1,1); lightSource(Position[0],Position[1],Position[2] , 0.1); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // Location of viewer for specular calculations glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local); // glColor sets ambient and diffuse color materials glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); } else glDisable(GL_LIGHTING); // Draw Bell towers bell(8,2,-6,.25); bell(-8,2,-6,.25); for (int i = -9; i <= 9; i+=2){ for (int j = -5; j <= 5; j +=4){ floorTiles(i,-.5,j,1.2,0); } } for (int i = -8; i <= 8; i+=2){ for (int j = -3; j <= 5; j +=4){ floorTiles(i,-.5,j,1.2,.5); } } // Draw Game grid for (int k = -4; k <= -1; k++){ cube(k,0,-4, .5,.5,.5 , 0); cube(k,0,4, .5,.5,.5 , 0); cube(-4,0,k, .5,.5,.5 , 0); cube(4,0,k, .5,.5,.5 , 0); } for (int k = 1; k <= 4; k++){ cube(k,0,-4, .5,.5,.5 , 0); cube(k,0,4, .5,.5,.5 , 0); cube(-4,0,k, .5,.5,.5 , 0); cube(4,0,k, .5,.5,.5 , 0); } for (int k = -10; k <= 10; k++){ cube(k,0,-6, .5,.5,.5 , 0); cube(k,0,6, .5,.5,.5 , 0); } for (int k = -6; k <= 6; k++){ cube(-10,0,k, .5,.5,.5 , 0); cube(10,0,k, .5,.5,.5 , 0); } for (int k = -4; k <= 4; k++){ cube(-8,0,k, .5,.5,.5 , 0); cube(8,0,k, .5,.5,.5 , 0); } for (int k = -6; k <= -5; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int k = -3; k <= 3; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int k = 5; k <= 6; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int j = -2; j <= -1; j++){ cube(j,0,-2, .5,.5,.5 , 0); cube(j,0,2, .5,.5,.5 , 0); cube(-2,0,j, .5,.5,.5 , 0); cube(2,0,j, .5,.5,.5 , 0); } for (int l = 1; l <= 2; l++){ cube(l,0,-2, .5,.5,.5 , 0); cube(l,0,2, .5,.5,.5 , 0); cube(-2,0,l, .5,.5,.5 , 0); cube(2,0,l, .5,.5,.5 , 0); } for (int i = -6; i <= 6; i++){ for (int j = -10; j <= 10; j++){ if (balls[i+6][j+10] == 1){ ball(j,0,i, 0.1,4); } } } // Draw ghosts and animate movement //Red Ghost Movement if (redTrack == 0){ posx1 += dx; ghost(posx1,0,-5 , 0.4, 0, 0); if (posx1 >= -7){ redTrack = 1; } glutIdleFunc(idle); } else if (redTrack == 1){ posz1 += dx; ghost(-7,0,posz1 , 0.4, 0, 0); if (posz1 >= 5){ redTrack = 2; } glutIdleFunc(idle); } else if (redTrack == 2){ posx1 -= dx; ghost(posx1,0,5 , 0.4, 0, 0); if (posx1 <= -9){ redTrack = 3; } glutIdleFunc(idle); } else if (redTrack == 3){ posz1 -= dx; ghost(-9,0,posz1 , 0.4, 0, 0); if (posz1 <= -5){ redTrack = 0; } glutIdleFunc(idle); } //Blue Ghost Movement if (blueTrack == 0){ posx2 += dx; ghost(posx2,0,-5 , 0.4, 0, 1); if (posx2 >= 5){ blueTrack = 1; } glutIdleFunc(idle); } else if (blueTrack == 1){ posz2 += dx; ghost(5,0,posz2 , 0.4, 0, 1); if (posz2 >= 5){ blueTrack = 2; } glutIdleFunc(idle); } else if (blueTrack == 2){ posx2 -= dx; ghost(posx2,0,5 , 0.4, 0, 1); if (posx2 <= -5){ blueTrack = 3; } glutIdleFunc(idle); } else if (blueTrack == 3){ posz2 -= dx; ghost(-5,0,posz2 , 0.4, 0, 1); if (posz2 <= -5){ blueTrack = 0; } glutIdleFunc(idle); } //Pink Ghost Movement if (pinkTrack == 0){ posx3 += dx; ghost(posx3,0,-5 , 0.4, 0, 2); if (posx3 >= 9){ pinkTrack = 1; } glutIdleFunc(idle); } else if (pinkTrack == 1){ posz3 += dx; ghost(9,0,posz3 , 0.4, 0, 2); if (posz3 >= 5){ pinkTrack = 2; } glutIdleFunc(idle); } else if (pinkTrack == 2){ posx3 -= dx; ghost(posx3,0,5 , 0.4, 0, 2); if (posx3 <= 7){ pinkTrack = 3; } glutIdleFunc(idle); } else if (pinkTrack == 3){ posz3 -= dx; ghost(7,0,posz3 , 0.4, 0, 2); if (posz1 <= -5){ pinkTrack = 0; } glutIdleFunc(idle); } //Orange Ghost Movement if (orangeTrack == 0){ posx4 += dx; ghost(posx4,0,-3 , 0.4, 0, 3); if (posx4 >= 3){ orangeTrack = 1; } glutIdleFunc(idle); } else if (orangeTrack == 1){ posz4 += dx; ghost(3,0,posz4 , 0.4, 0, 3); if (posz4 >= 0){ orangeTrack = 2; } glutIdleFunc(idle); } else if (orangeTrack == 2){ posx4 += dx; ghost(posx4,0,0 , 0.4, 0, 3); if (posx4 >= 5){ orangeTrack = 3; } glutIdleFunc(idle); } else if (orangeTrack == 3){ posz4 -= dx; ghost(5,0,posz4 , 0.4, 0, 3); if (posz4 <= -4){ orangeTrack = 4; } glutIdleFunc(idle); } else if (orangeTrack == 4){ posx4 += dx; ghost(posx4,0,-4 , 0.4, 0, 3); if (posx4 >= 7){ orangeTrack = 5; } glutIdleFunc(idle); } else if (orangeTrack == 5){ posz4 += dx; ghost(7,0,posz4 , 0.4, 0, 3); if (posz4 >= 4){ orangeTrack = 6; } glutIdleFunc(idle); } else if (orangeTrack == 6){ posx4 -= dx; ghost(posx4,0,4 , 0.4, 0, 3); if (posx4 <= 5){ orangeTrack = 7; } glutIdleFunc(idle); } else if (orangeTrack == 7){ posz4 += dx; ghost(5,0,posz4 , 0.4, 0, 3); if (posz4 >= 5){ orangeTrack = 8; } glutIdleFunc(idle); } else if (orangeTrack == 8){ posx4 -= dx; ghost(posx4,0,5 , 0.4, 0, 3); if (posx4 <= -5){ orangeTrack = 9; } glutIdleFunc(idle); } else if (orangeTrack == 9){ posz4 -= dx; ghost(-5,0,posz4 , 0.4, 0, 3); if (posz4 <= 4){ orangeTrack = 10; } glutIdleFunc(idle); } else if (orangeTrack == 10){ posx4 -= dx; ghost(posx4,0,4 , 0.4, 0, 3); if (posx4 <= -7){ orangeTrack = 11; } glutIdleFunc(idle); } else if (orangeTrack == 11){ posz4 -= dx; ghost(-7,0,posz4 , 0.4, 0, 3); if (posz4 <= -4){ orangeTrack = 12; } glutIdleFunc(idle); } else if (orangeTrack == 12){ posx4 += dx; ghost(posx4,0,-4 , 0.4, 0, 3); if (posx4 >= -5){ orangeTrack = 13; } glutIdleFunc(idle); } else if (orangeTrack == 13){ posz4 += dx; ghost(-5,0,posz4 , 0.4, 0, 3); if (posz4 >= 0){ orangeTrack = 14; } glutIdleFunc(idle); } else if (orangeTrack == 14){ posx4 += dx; ghost(posx4,0,0 , 0.4, 0, 3); if (posx4 >= -3){ orangeTrack = 15; } glutIdleFunc(idle); } else if (orangeTrack == 15){ posz4 -= dx; ghost(-3,0,posz4 , 0.4, 0, 3); if (posz4 <= -3){ orangeTrack = 16; } glutIdleFunc(idle); } else if (orangeTrack == 16){ posx4 += dx; ghost(posx4,0,-3 , 0.4, 0, 3); if (posx4 >= 0){ orangeTrack = 0; } glutIdleFunc(idle); } // Win condition if (score == 132){ glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(400,400); Print("Congratulations: You Win"); pos[0] = 0; pos[1] = 0; } // Detect ghost collision if ((pos[0] == posx1 && pos[1] == posz1) || (pos[0] == posx2 && pos[1] == posz2) || (pos[0] == posx3 && pos[1] == posz3) || (pos[0] == posx4 && pos[1] == posz4)){ lives--; dead = 1; if (lives == 0){ done = 1; } } // Draw Pacman if (dead == 0){ pacman(pos[0],0,pos[1], .4,0,press); } else if (done == 1){ glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(400,400); Print("Game Over"); pos[0] = 0; pos[1] = 0; } else{ pos[0] = 0; pos[1] = 0; dead = 0; pacman(pos[0],0,pos[1], .4,0,press); glutPostRedisplay(); } glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(5,5); Print("Lives:%i Score=%i",lives,score); // Render the scene and make it visible glFlush(); glutSwapBuffers(); }
void display(void) { // clear all pixels glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; // draw white polygon (square) of unit length centered at the origin // Note that vertices must generally go counterclockwise // Change from the first program, in that I just made it white. // The old OpenGL code of using glBegin... glEnd no longer appears. // The new version uses vertex buffer objects from init. // Does the order of drawing matter? What happens if I draw the ground // after the pillars? I will show this in class glUniform1i(islight,0) ; // Turn off lighting (except on teapot, later) glUniform1i(istex,texturing) ; drawtexture(FLOOR,texNames[0]) ; // Texturing floor // drawobject(FLOOR) ; glUniform1i(istex,0) ; // Other items aren't textured // Now draw several cubes with different transforms, colors // I continue to use the deprecated push-pop and matrix mode // Since it is convenient (or you have to write your own stack). glMatrixMode(GL_MODELVIEW) ; // 1st pillar glPushMatrix() ; glTranslatef(-0.4,-0.4,0.0) ; drawcolor(CUBE, 0) ; glPopMatrix() ; // 2nd pillar glPushMatrix() ; glTranslatef(0.4,-0.4,0.0) ; drawcolor(CUBE, 1) ; glPopMatrix() ; // 3rd pillar glPushMatrix() ; glTranslatef(0.4,0.4,0.0) ; drawcolor(CUBE, 2) ; glPopMatrix() ; // 4th pillar glPushMatrix() ; glTranslatef(-0.4,0.4,0.0) ; drawcolor(CUBE, 3) ; glPopMatrix() ; // Draw the glut teapot // This is using deprecated old-style OpenGL certainly /* New for Demo 3; add lighting effects */ { const GLfloat one[] = {1, 1, 1, 1}; const GLfloat medium[] = {0.5, 0.5, 0.5, 1}; const GLfloat small[] = {0.2, 0.2, 0.2, 1}; const GLfloat high[] = {100} ; const GLfloat zero[] = {0.0, 0.0, 0.0, 1.0} ; const GLfloat light_specular[] = {1, 1, 0, 1}; const GLfloat light_specular1[] = {0, 0.5, 1, 1}; const GLfloat light_direction[] = {0.5, 0, 0, 0}; // Dir light 0 in w const GLfloat light_position1[] = {0, -0.5, 0, 1}; GLfloat light0[4], light1[4] ; // Set Light and Material properties for the teapot // Lights are transformed by current modelview matrix. // The shader can't do this globally. // So we need to do so manually. transformvec(light_direction, light0) ; transformvec(light_position1, light1) ; glUniform3fv(light0dirn, 1, light0) ; glUniform4fv(light0color, 1, light_specular) ; glUniform4fv(light1posn, 1, light1) ; glUniform4fv(light1color, 1, light_specular1) ; // glUniform4fv(light1color, 1, zero) ; glUniform4fv(ambient,1,small) ; glUniform4fv(diffuse,1,medium) ; glUniform4fv(specular,1,one) ; glUniform1fv(shininess,1,high) ; // Enable and Disable everything around the teapot // Generally, we would also need to define normals etc. // But glut already does this for us if (DEMO > 4) glUniform1i(islight,lighting) ; // turn on lighting only for teapot. } // ** NEW ** Put a teapot in the middle that animates glColor3f(0.0,1.0,1.0) ; // Deprecated command to set the color glPushMatrix() ; // I now transform by the teapot translation for animation glTranslatef(teapotloc, 0.0, 0.0) ; // The following two transforms set up and center the teapot // Remember that transforms right-multiply the stack glTranslatef(0.0,0.0,0.1) ; glRotatef(rotamount, 0.0, 0.0, 1.0); glRotatef(90.0,1.0,0.0,0.0) ; glutSolidTeapot(0.15) ; glUniform1i(islight,0) ; // turn off lighting glPopMatrix() ; // Does order of drawing matter? // What happens if I draw the ground after the pillars? // I will show this in class. // drawobject(FLOOR) ; // don't wait! // start processing buffered OpenGL routines glutSwapBuffers() ; glFlush (); }
void display() { Hi=cvQueryFrame (hit); hi=Hi; //cvFlip(Hi,hi,1); /*cvCreateTrackbar( "huehigher", "blobbed lappy", &hh,180,harshit); cvCreateTrackbar( "huelower", "blobbed lappy", &hl,180,harshit); cvCreateTrackbar( "saturationhigher", "blobbed lappy", &sh,255,harshit); cvCreateTrackbar( "saturationlower", "blobbed lappy", &sl,255,harshit); cvCreateTrackbar( "valuehiger", "blobbed lappy",&vh,255,harshit); cvCreateTrackbar( "valuelower", "blobbed lappy",&vl,255,harshit); */ blobbing(hi,"binary lappy","blobbed lappy",0); glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); float greaterx,greatery, greaterz , lesserx, lessery, lesserz; if (x<X) { greaterx=x; greatery=y; greaterz=counthand1; lesserx=X; lessery=Y; lesserz=counthand2; } else { greaterx=X; greatery=Y; greaterz=counthand2; lesserx=x; lessery=y; lesserz=counthand1; } GLfloat y1=-4 + (-1*(greaterx-320)*1.2/80); GLfloat y2= -4+(-1*(lesserx-320)*1.2/80); GLfloat sum=y1+y2,diff=y1-y2; GLfloat Centre1[]= {6-1*greaterz/scalingfactor,y1 , -1*(greatery-240)*1.2/60 }; GLfloat Centre2[]= {6-1* lesserz/scalingfactor, y2, -1*(lessery-240)*1.2/60 }; if (y1>-2) Centre1[1]=-2; if (y1<-6) Centre1[1]=-6; if(y2>-2) Centre2[1]=-2; if(y2<-6) Centre2[1]=-6; me.hand1next= Sphere( Centre1, .5); me.hand2next= Sphere( Centre2, .5); // Moving the computer's hands... //to put the comp suddenly backwards if (inmoveornot||inmoveornot) {//inmoveornot=1; if (q1>x_initpos_hand1) { q1=q1-compspeed; } else { q1=x_initpos_hand1; handonedone=0; if (jumphandsup1==1) { jumphandsup1=0; tempcomp1[2]=tempcomp1[2]+.15; } else { jumphandsup1=1; tempcomp1[2]=tempcomp1[2]-.15; } } comp.hand1next=Sphere(tempcomp1,0.5); tempcomp1[0]=q1; tempcomp1[1]=((q1-x_initpos_hand1)*1.0)/(xrandom_hand1-x_initpos_hand1)*(yrandom_hand1-y_initpos_hand1)+y_initpos_hand1; tempcomp1[2]=((q1-x_initpos_hand1)*1.0)/(xrandom_hand1-x_initpos_hand1)*(zrandom_hand1-z_initpos_hand1)+z_initpos_hand1; if (q2>x_initpos_hand2) { q2=q2-compspeed; } else { q2=x_initpos_hand2; handtwodone=0; if (jumphandsup2==1) { jumphandsup2=0; tempcomp2[2]=tempcomp2[2]+.15; } else { jumphandsup2=1; tempcomp2[2]=tempcomp2[2]-.15; } } comp.hand2next=Sphere(tempcomp2,0.5); tempcomp2[0]=q2; tempcomp2[1]=((q2-x_initpos_hand2)*1.0)/(xrandom_hand2-x_initpos_hand2)*(yrandom_hand2-y_initpos_hand2)+y_initpos_hand2; tempcomp2[2]=((q2-x_initpos_hand2)*1.0)/(xrandom_hand2-x_initpos_hand2)*(zrandom_hand2-z_initpos_hand2)+z_initpos_hand2; if (handonedone==0 && handtwodone==0) { inmoveornot=0; handonedone=handtwodone=1; } } else { if (count1==1) { srand((unsigned)time (NULL)); xrandom_hand1 =rand()%2+5; yrandom_hand1 =rand()%1-3.5; zrandom_hand1 =rand()%1; count1 =0; } tempcomp1[0]=q1; tempcomp1[1]=((q1-x_initpos_hand1)*1.0)/(xrandom_hand1-x_initpos_hand1)*(yrandom_hand1-y_initpos_hand1)+y_initpos_hand1; tempcomp1[2]=((q1-x_initpos_hand1)*1.0)/(xrandom_hand1-x_initpos_hand1)*(zrandom_hand1-z_initpos_hand1)+z_initpos_hand1; if (q1>=abs(xrandom_hand1-x_initpos_hand1)||decreasestarthand1) { q1=q1-compspeed; decreasestarthand1=1; } else { q1=compspeed+q1; }; if (q1<=0) { q1=0; decreasestarthand1=0; count1 =1; } comp.hand1next=Sphere(tempcomp1,0.5); if (count2==1) { srand((unsigned)(time (NULL)*13)); xrandom_hand2 =-1*rand()%2-5; yrandom_hand2 =rand()%1-4.5; zrandom_hand2 =rand()%1; count2 =0; } tempcomp2[0]=q2; tempcomp2[1]=((q2-x_initpos_hand2)*1.0)/(xrandom_hand2-x_initpos_hand2)*(yrandom_hand2-y_initpos_hand2)+y_initpos_hand2; tempcomp2[2]=((q2-x_initpos_hand2)*1.0)/(xrandom_hand2-x_initpos_hand2)*(zrandom_hand2-z_initpos_hand2)+z_initpos_hand2; if (q2>=abs(xrandom_hand2-x_initpos_hand2)||decreasestarthand2) { q2=q2-compspeed; decreasestarthand2=1; } else { q2=q2+compspeed; }; if (q2<=0) { q2=0; decreasestarthand2=0; count2 =1; } comp.hand2next=Sphere(tempcomp2,0.5); } if (countforcolor>1) //the color of screen should remain red or cyan until 6 iterations { countforcolor=0; increasingcountforcolor=0; mehit=0; comphit=0; nohit=1; } if (increasingcountforcolor==1) //increases the no. of iterations {countforcolor++; } //.....in the below else parts the colors are decide in the event of collision and //......initialising of increasingcountforcolor is done //Determines collission of the hands with hands+bodies... if(isCollission(me.hand1next,me,comp) == false ) { me.hand1=me.hand1next; } else { mehit=0; nohit=0; comphit=1; increasingcountforcolor=1; //printf("yeah the comp has been hit\n"); } if(isCollission(me.hand2next,me,comp) == false ) { me.hand2=me.hand2next; } else {mehit=0; nohit=0; comphit=1; increasingcountforcolor=1; //printf("yeah the comp has been hit\n"); } if(isCollission(comp.hand1next,comp,me) == false ) { comp.hand1=comp.hand1next; } else {mehit=1; nohit=0; comphit=0; increasingcountforcolor=1; //printf("you have been hit\n"); } if(isCollission( comp.hand2next,comp,me) == false ) { comp.hand2=comp.hand2next; } else {mehit=1; nohit=0; comphit=0; increasingcountforcolor=1; //printf("sorry,sorry , sorry you have been hit\n"); } init(); //displaying the hands and bodies... //me.dispPlayer(); dont intend to display me's body headcolor=1;comphandcolor=0;myhandcolor=0; comp.dispPlayer(); headcolor=0;comphandcolor=0;myhandcolor=1; me.hand1.dispSphere(); me.hand2.dispSphere(); headcolor=0;comphandcolor=1;myhandcolor=0; comp.hand1.dispSphere(); comp.hand2.dispSphere(); glLoadIdentity (); gluLookAt (xpos, ypos, zpos, xdir, ydir, zdir, 0.0, 0,1); glutSwapBuffers(); glFlush(); for(int i=0;i<score->height;i++){ for(int j=0;j<score->width;j++){ for(int k=0;k<score->nChannels;k++){ score->imageData[i * score->widthStep +j * score->nChannels +k]=0; } } } sprintf(&stringme[11],"%d",me.score); sprintf(&stringcomp[9],"%d",comp.score); CvFont font; cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,1,1); cvPutText(score,stringme,cvPoint(50,50),&font,cvScalar(255,0,0)); cvPutText(score,stringcomp, cvPoint(370,50),&font,cvScalar(0,0,255)); cvShowImage("Score",score); if (me.score>=1000) { char stringmeend[22]="YOU WIN"; //deciding who wins for(int i=0;i<score->height;i++){ for(int j=0;j<score->width;j++){ for(int k=0;k<score->nChannels;k++){ score->imageData[i * score->widthStep +j * score->nChannels +k]=0; } } } cvPutText(score,stringmeend,cvPoint(50,50),&font,cvScalar(255,0,0)); cvShowImage("Score",score); cvWaitKey(); exit (0); } if (comp.score>=1000) { char stringcompend[29]="YOU LOOSE."; //decides who loose for(int i=0;i<score->height;i++){ for(int j=0;j<score->width;j++){ for(int k=0;k<score->nChannels;k++){ score->imageData[i * score->widthStep +j * score->nChannels +k]=0; } } } cvPutText(score,stringcompend, cvPoint(370,50),&font,cvScalar(0,0,255)); cvWaitKey(); exit (0); } }
void display() { renderTextures(); /* glClearColor(0.0f, 0.0f, 0.2f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, 100, 0, 100); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glPushAttrib(GL_VIEWPORT_BIT); glLoadIdentity(); //glTranslatef(0, 0, 1); //// Bottom left //glViewport(0, 0, sWidth/2, sHeight/2); //glBindTexture(GL_TEXTURE_2D, imgTexture); //renderQuad(); //// Bottom Right //glViewport(sWidth/2, 0, sWidth, sHeight/2); //glBindTexture(GL_TEXTURE_2D, outlineTexture); //renderQuad(); // Top left //glViewport(0, sHeight/2, sWidth/2, sHeight); glBindTexture(GL_TEXTURE_2D, depthTexture); glEnable(GL_TEXTURE_2D); renderQuad(); //// Top Right //glViewport(sWidth/2, sHeight/2, sWidth, sHeight); //glBindTexture(GL_TEXTURE_2D, normalTexture); //renderQuad(); glDisable(GL_TEXTURE_2D); glPopAttrib(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); //*/ ///* glClearColor(0.0f, 0.0f, 0.2f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // bind the first texture for rendering glBindTexture(GL_TEXTURE_2D, depthTexture); // regenerate the mipmap images as the texture has changed //glGenerateMipmapEXT(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D); glTranslatef(-1.0f, 1.0f, -4.5f); glRotatef(-xrot, 1.0f, 0.0f, 0.0f); glRotatef(-yrot, 0.0f, 1.0f, 0.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); drawCube(); // draw the second cube glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, normalTexture); glEnable(GL_TEXTURE_2D); glTranslatef(1.0f, 1.0f, -4.5f); glRotatef(-xrot, 1.0f, 0.0f, 0.0f); glRotatef(-yrot, 0.0f, 1.0f, 0.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); drawCube(); // draw the third cube glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, imgTexture); glEnable(GL_TEXTURE_2D); glTranslatef(1.0f, -1.0f, -4.5f); glRotatef(-xrot, 1.0f, 0.0f, 0.0f); glRotatef(-yrot, 0.0f, 1.0f, 0.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); drawCube(); // draw the fourth cube glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, imgTexture); glEnable(GL_TEXTURE_2D); glTranslatef(-1.0f, -1.0f, -4.5f); glRotatef(-xrot, 1.0f, 0.0f, 0.0f); glRotatef(-yrot, 0.0f, 1.0f, 0.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); sobelFilter->use(); sobelFilter->sendUniform("colorMap", 0); sobelFilter->sendUniform("width", texWidth); sobelFilter->sendUniform("height", texHeight); drawCube(); sobelFilter->disable(); glDisable(GL_TEXTURE_2D); //*/ xrot += xspeed; yrot += yspeed; //fps(); glutSwapBuffers(); }
void display (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_empty_board (); draw_pieces (); glutSwapBuffers (); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glVertexAttrib4fv(vAmbientDiffuseColor, vec4(.7, .7, .7, 1)); glVertexAttrib4fv(vSpecularColor, vec4(.7f,.7f,.7f,1.0f)); glVertexAttrib1f(vSpecularExponent, 30); glUniform4fv(light_position, 1, mv*vec4(10, 10, 50, 1)); glUniform4fv(light_color, 1, vec4(1,1,1,1)); glUniform4fv(ambient_light, 1, vec4(.1, .1, .1, 1)); //mat4 camera = mv = LookAt(vec4(0,0,5.0+z_distance,1),vec4(0,0,0,1),vec4(0,1,0,0)) * RotateX(-90.0) * RotateX(view_rotx) * RotateY(view_roty); mat4 camera = mv = LookAt(vec4(0,0,5.0+z_distance,1),vec4(0,0,0,1),vec4(0,1,0,0)) * RotateX(-90.0); //RotateX(view_rotx) * RotateY(view_roty); /*if ( true ) { glUseProgram(light_program); glUniformMatrix4fv(model_view, 1, GL_TRUE, mv); glVertexAttrib4fv(vAmbientDiffuseColor, vec4(.2, 0.2, 0.2, 1)); glVertexAttrib4fv(vSpecularColor, vec4(.9f,0.9f,.9f,1.0f)); glVertexAttrib1f(vSpecularExponent, 10.0); glUniform4fv(light_position, 1, mv*vec4(50, 50, 50, 1)); glUniform4fv(light_color, 1, vec4(1,1,1,1)); glUniform4fv(ambient_light, 1, vec4(.5, .5, .5, 5)); glBindVertexArray( spherevao[0] ); glDrawArrays( GL_QUAD_STRIP, 0, VertexCount ); }*/ //mat4 camera = mv = LookAt(vec4(0,0,5.0+z_distance,1),vec4(0,0,0,1),vec4(0,1,0,0))* RotateX(view_rotx) * RotateY(view_roty) * RotateZ(view_rotz); if ( true ) { glUniformMatrix4fv(model_view, 1, GL_TRUE, mv); glActiveTexture(GL_TEXTURE0); //mat4 camera = mv = LookAt(vec4(0,0,5.0+z_distance,1),vec4(0,0,0,1),vec4(0,1,0,0)) * RotateX(-90.0); //RotateX(view_rotx) * RotateY(view_roty); // mv = mv * RotateZ(rotateYEarth); glUniformMatrix4fv(model_view, 1, GL_TRUE, mv * RotateZ(rotateYEarth)*Translate(0,0,0)); glBindTexture(GL_TEXTURE_2D, texName[0]); //which texture do we want? glDrawArrays( GL_QUAD_STRIP, 0, VertexCount ); // CLOUD //glUniformMatrix4fv(model_view, 1, GL_TRUE, mv*RotateZ(rotateYEarth / 2)*Scale(1.02,1.02,1.02)*Translate(0,0,0)); //glBindTexture(GL_TEXTURE_2D, texName[1]); //which texture do we want? //glDrawArrays( GL_QUAD_STRIP, 0, VertexCount ); } /* mv = camera * RotateY(90)* Translate(0,0,1); glUniformMatrix4fv(model_view, 1, GL_TRUE, mv); glBindTexture(GL_TEXTURE_2D, texName[1]); //which texture do we want? glDrawArrays( GL_TRIANGLES, 0, 6 ); mv = camera* RotateY(-90) * Translate(0,0,1); glUniformMatrix4fv(model_view, 1, GL_TRUE, mv); glBindTexture(GL_TEXTURE_2D, texName[2]); //which texture do we want? glDrawArrays( GL_TRIANGLES, 0, 6 ); */ glFlush(); glutSwapBuffers(); }
static void render(void) { glClearColor(0.0f, 0.25f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glUseProgram(g_resources.program); glUniform1f(g_resources.uniforms.timer, g_resources.timer); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, g_resources.textures[0]); glUniform1i(g_resources.uniforms.textures[0], 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, g_resources.textures[1]); glUniform1i(g_resources.uniforms.textures[1], 1); glBindBuffer(GL_ARRAY_BUFFER,g_resources.color_buffer); glVertexAttribPointer(g_resources.attributes.color, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, (void*)0 ); glEnableVertexAttribArray(g_resources.attributes.color); glBindBuffer(GL_ARRAY_BUFFER,g_resources.texcood_buffer); glVertexAttribPointer(g_resources.attributes.texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0 ); glEnableVertexAttribArray(g_resources.attributes.texcoord); glBindBuffer(GL_ARRAY_BUFFER, g_resources.vertex_buffer); glVertexAttribPointer( g_resources.attributes.position, /* attribute */ 4, /* size */ GL_FLOAT, /* type */ GL_FALSE, /* normalized? */ sizeof(GLfloat)*4, /* stride */ (void*)0 /* array buffer offset */ ); glEnableVertexAttribArray(g_resources.attributes.position); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_resources.element_buffer); glDrawElements( GL_TRIANGLES, /* mode */ 6, /* count */ GL_UNSIGNED_SHORT, /* type */ (void*)0 /* element array buffer offset */ ); glDisableVertexAttribArray(g_resources.attributes.position); glClear(GL_DEPTH_BUFFER_BIT); glutSwapBuffers(); }
/* * Display the scene */ void display() { /* Coordinates */ double x = 1; double y = 1; double z = 1; /* Time step */ double dt = 0.001; // Clear the image glClear(GL_COLOR_BUFFER_BIT); // Reset previous transforms glLoadIdentity(); // Set view angle glRotated(ph,1,0,0); glRotated(th,0,1,0); // Draw 10 pixel yellow points glColor3f(0.0,1.0,0.5); glPointSize(1); glScaled(0.045, 0.045, 0.045); // Scale the vertex placement int i; for (i=0; i < 50000; i++) { double dx = s*(y-x); double dy = x*(r-z)-y; double dz = x*y - b*z; x += dt*dx; y += dt*dy; z += dt*dz; glBegin(GL_POINTS); glVertex4d(x,y,z,w); glEnd(); } // Draw axes in white glColor3f(1,1,1); glBegin(GL_LINES); glVertex3d(0,0,0); glVertex3d(30,0,0); glVertex3d(0,0,0); glVertex3d(0,30,0); glVertex3d(0,0,0); glVertex3d(0,0,30); glEnd(); // Label axes glRasterPos3d(30,0,0); Print("X"); glRasterPos3d(0,30,0); Print("Y"); glRasterPos3d(0,0,30); Print("Z"); // Display parameters glWindowPos2i(10,10); Print("Louis BOUDDHOU: View Angle = %d,%d %s",th,ph, " 3D"); // Flush and swap glFlush(); glutSwapBuffers(); }
void display() { glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */ if(view==0) { display1(); } else if (view==1) { display2(); } else if(view==2) { // Erase the window and the depth buffer glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glLoadIdentity(); // Set the look at position for perspective projection gluLookAt( Ex, Ey, Ez, Ex + lx, Ey, Ez+lz, 0.0, 1, 0.0); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); Sky(1000); glPopMatrix(); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); // Light switch if (light) { // Translate intensity to color vectors float Ambient[] = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0}; float Diffuse[] = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0}; float Specular[] = {0.01*specular,0.01*specular,0.01*specular,1.0}; // Light position float Position[]={0,1000,5000}; // Draw light position as ball (still no lighting here) glColor3f(1,1,1); ball(Position[0],Position[1],Position[2] , 0.2); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // glColor sets ambient and diffuse color materials glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); } else glDisable(GL_LIGHTING); if(opt==1) { glPushMatrix(); glTranslatef( Ex + lx,0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car1); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } else if(opt==2) { glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car2); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } cylinder(); Road(); for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(-50,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(170,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(-70,-10,i); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(70,-10,i); glRotated(90,0,1,0); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(-38,86.5,i+43); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(55,87,i+30); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(-50,-10,i); glScaled(10,10,10); trafficsignal(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(0,0,i+40); zebracrossing(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(200,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-250,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(350,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-400,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(e=0; e<=1000; e+=155) { if(e%2==0) { glPushMatrix(); glTranslated(-16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } else { glPushMatrix(); glTranslated(16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(65,0,i); glScaled(10,10,10); roadsign(); glPopMatrix(); } xpos = xpos + xvel; if(xpos >= 30) { xvel = -xvel; } if( xpos <2) { xvel = -xvel; } glPushMatrix(); glTranslated(0,xpos,900); glRotated(-90,0,0,1); glRotated(-90,0,1,0); glScaled(2,2,2); glColor3f(1,1,1); glCallList(dragon); glPopMatrix(); glWindowPos2i(5,5); glColor3f(1,1,1); Print("Speed=%f",1,jump); } // Render the scene and make it visible ErrCheck("display"); glFlush(); glutSwapBuffers(); }
/* ======================================================================================================================= Display function. Where the magic happens and everything is drawn. ======================================================================================================================= */ void display(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* adjust for zoom value */ gluPerspective(50 * zoom, (float) glutGet(GLUT_WINDOW_WIDTH) / (float) glutGet(GLUT_WINDOW_HEIGHT), 0.001, 40.0); glMatrixMode(GL_MODELVIEW); /* do rotation things */ alpha = alpha + (float) inc; if(alpha > (float) 360.0) alpha -= (float) 360.0; beta = beta + (float) inc2; if(beta > (float) 360.0) beta -= (float) 360.0; /* normalise any normals which aren't in unit form */ glEnable(GL_NORMALIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* draw the fog */ fog(); glPushMatrix(); /* translate whole scene so we can actually see it */ glTranslatef((float) 0.0, -(float) 0.5, -(float) 5); /* rotate by rotation values */ glRotatef(beta, (float) 1.0, (float) 0.0, (float) 0.0); glRotatef(-alpha, (float) 0.0, (float) 1.0, (float) 0.0); /* it was a bit big... */ glScalef(0.50, 0.50, 0.50); /* set shade mode */ glShadeModel(shademode); glPushMatrix(); /* draw the floor */ glScalef(scale * 5, scale * 5, scale * 5); glRotatef(180, 0, 1.0, 1.0); drawCheck(20, 20, BLUE, YELLOW); /* draw ground */ glPopMatrix(); /* set up the lights */ glTranslatef(0.3, 0, 1.25); glEnable(GL_LIGHTING); /* this is a positioned light */ glEnable(GL_LIGHT0); /* this is a directed light */ glEnable(GL_LIGHT1); /* this is a spotlight (not initiated til later) */ glEnable(GL_LIGHT2); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* set the ambient light */ GLfloat ambientColor[] = { 0.2, 0.2, 0.2, 1.0 }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GLfloat lightColor0[] = { 0.5, 0.5, 0.5, 1.0 }; GLfloat lightPos0[] = { 0.0f, 1.5f, -1.0f, 0.0f }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GLfloat lightColor1[] = { 0.8f, 0.8f, 0.8f, 1.0f }; GLfloat lightPos1[] = { 1.0f, 2.0f, -2.0f, 0.0f }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); /* draw the table */ glPushMatrix(); glTranslatef(-0.3, 0, -1.25); glRotatef(180, 0, 1.0, 1.0); /*~~~~~~~~~~~~~~~~~~~~~~~*/ float cylbase = 0.60; float cyltop = 0.15; float cylheight = 1.0; float tableheight = 0.10; float tablecirc = 0.90; /*~~~~~~~~~~~~~~~~~~~~~~~*/ setMaterial(finTable); setColor(TABLE2); gluCylinder(quadratic, cylbase, cyltop, cylheight, splines * LOD, splines * LOD); glTranslatef(0, 0, cylheight); gluDisk(quadratic, 0.0, cyltop, splines * LOD, splines * LOD); gluCylinder(quadratic, tablecirc, tablecirc, tableheight, splines * LOD, splines * LOD); gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD); glTranslatef(0, 0, tableheight); gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD); setMaterial(finDefault); glPopMatrix(); glPushMatrix(); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* initiate the spotlight */ GLfloat light_ambient2[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse2[] = { 0.0, 0.3, 0, 1.0 }; GLfloat light_specular2[] = { 0.0, 0.3, 0, 1.0 }; GLfloat lightPos2[] = { 0.0f, 3.0f, 0.0f, 0.0f }; GLfloat spot_direction[] = { 0, -1.0, 0 }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT2, GL_AMBIENT, light_ambient2); glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse2); glLightfv(GL_LIGHT2, GL_SPECULAR, light_specular2); glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 30.0); glLightfv(GL_LIGHT2, GL_POSITION, lightPos2); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spot_direction); /* draw the chairs and rotate them around the table */ glRotatef(270, 0.0, 1.0, 0.0); glTranslatef(-1.5, 0, 1.5); glPushMatrix(); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(90, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(180, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(270, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); /* draw the cups/forks and rotate around the table */ glPushMatrix(); glTranslatef(0.35, 1.1, -0.25); cups(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(90, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(180, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(270, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPopMatrix(); /* draw the teapot */ glPushMatrix(); /* put on table */ glTranslatef(0.3, 1.3, -1.25); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* trans values for animation */ static int rotateval = 1; static int rotatevalx = 0; static float transvaly = 0; static float transvalx = 0; /* clock values for animation */ static int beginslow = 0; static int slowclock = 0; static int pourclock = 0; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* only animate when playing */ if(ani_play) { { /*~~~*/ int ii; /*~~~*/ for(ii = 0; ii < speed; ii++) { { /* section where teapot slows */ if((beginslow)) { { if(((20 - slowclock / 10) > 0)) { rotateval = rotateval + (20 - slowclock / 10); slowclock++; } else { { /* section where teapot is pouring */ if(pourclock < 90) { { rotatevalx = pourclock / 2; transvaly = ((double) pourclock) / (double) 200; transvalx = ((double) pourclock) / (double) 400; } } else if(pourclock < 135) { /* teapot in mid air */ rotatevalx = 45; transvaly = 90.0 / 200; transvalx = 90.0 / 400; } else if(pourclock < 225) { { /* teapot is being set down */ rotatevalx = 45 - (pourclock - 135) / 2; transvaly = 90.0 / 200 - ((double) pourclock - 135) / (double) 200; transvalx = 90.0 / 400 - ((double) pourclock - 135) / (double) 400; } } else if(pourclock < 300) { /* teapot is back on table */ rotatevalx = 0; transvaly = 0; transvalx = 0; } else { { /* reset variables for next play */ ani_play = 0; ani_clock = 0; rotateval = 1; ani_direction = 0; slowclock = 0; pourclock = -speed; beginslow = 0; rotatevalx = 0; transvaly = 0; transvalx = 0; } } pourclock++; } } } } else if(ani_clock < 200) { /* teapot is speeding up it's spin */ rotateval = rotateval + ani_clock / 10; } else if(ani_clock < 500) { { /* teapot is at constant spin */ rotateval = rotateval + 20; if(ani_clock == 300) { /* choose the cup it will stop at */ ani_direction = rand() % 4 + 1; } } } if(rotateval > 360) rotateval -= 360; if ( (!beginslow) && (ani_direction != 0) && ( ( (rotateval >= ani_direction * 90 - SLOWMAGIC - 20) && (rotateval <= ani_direction * 90 - SLOWMAGIC) ) || ( (rotateval >= ani_direction * 90 - SLOWMAGIC + 340) && (rotateval <= ani_direction * 90 - SLOWMAGIC + 360) ) ) ) { /* choose opportune moment to slow down */ beginslow = 1; rotateval = ani_direction * 90 - SLOWMAGIC + 360; if(rotateval > 360) rotateval -= 360; } ani_clock++; } } } /* apply transformations */ } glRotatef(rotateval, 0, 1.0, 0); glTranslatef(transvalx, transvaly, 0); glRotatef(-rotatevalx, 0, 0, 1.0); /* apply texture */ glBindTexture(GL_TEXTURE_2D, texture[1]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); /* apply finish */ setMaterial(finPot); glutSolidTeapot(0.2); setMaterial(finDefault); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPopMatrix(); /* 3D stuff is done */ glFlush(); /* draw text overlay */ glDisable(GL_NORMALIZE); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ char speedstring[20]; char str[500] = "<Z> and <z>: zoom in/out\n<X> or <x>: Start/Stop X rotation\n<Y> or <y> Start/Stop Y Rotation\n<A> or <a>: Start animation\n<F> or <f>: Speed up animation\n<S> or <s>: Slow down animation\n<T> or <t>: Pause animation\n<C> or <c>: Resume the animation\n<p>: switch the rendering to the flat shaded polygonization.\n<P> switch the rendering to the smooth shaded polygonization.\n<q> or <Q>: change fog mode\nspeed: "; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ sprintf(speedstring, "%d", speed); strcat(str, speedstring); strcat(str, "\nLOD: "); sprintf(speedstring, "%d", LOD); strcat(str, speedstring); strcat(str, "\nFog Mode: "); switch(fogfilter) { { case 0: strcat(str, "GL_EXP"); break; case 1: strcat(str, "GL_EXP2"); break; case 2: strcat(str, "GL_LINEAR"); break; case 3: strcat(str, "NO FOG"); break; } } bitmap_output(30, 30, str, GLUT_BITMAP_HELVETICA_12); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); /* draw transparent box for text */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f((float) 0, (float) 0, (float) 0, (float) 0.6); glRecti(30 - 10, 30 - 20, 40 + 350, 30 + 250); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); glutSwapBuffers(); }
void display(void) { int row, col; GLfloat patch[4][4][3]; float texel[2][2][2] = { {{0.0, 0.0}, {1.0, 0.0}}, {{0.0, 1.0}, {1.0, 1.0}}}; glEnable(GL_MAP2_TEXTURE_COORD_2); glutSetWindow(main_window); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(X, Y, Z, 0.0, 0.0, 5.0, 0.0, 0.0, 1.0); buildSurfaceOfRotation(); /** AIRPLANE STUFF **/ glPushMatrix(); glTranslatef(-35, 35, -7.0); glTranslatef(theta, -theta, theta/5); glRotatef(45, 0.0, 0.0, 1.0); /**** BODY ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &bodyControlPoints[3*row][3*col][0]); //glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); /**** LEFT WING ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); glRotatef(180, 0.0, 0.0, 1.0); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &wingControlPoints[3*row][3*col][0]); //glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); /**** RIGHT WING ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); //glRotatef(180, 0.0, 0.0, 1.0); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &wingControlPoints[3*row][3*col][0]); //glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); /* glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, airplaneTexID); */ switchTextures(AIRPLANE); /* LEFT DECAL */ glPushMatrix(); glTranslatef(8.0, 0.0, 0.0); glTranslatef(0.0, -6.5, 0.0); glTranslatef(0.0, 0.0, 0.05); glRotatef(6.35, 1.0, 1.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glRotatef(25, 0.0, 1.0, 0.0); glBegin(GL_POLYGON); glTexCoord2f(0,0); glVertex3f(0, 0, 0); glTexCoord2f(1,0); glVertex3f(0, 7, 0); glTexCoord2f(1,1); glVertex3f(2, 7, 0); glTexCoord2f(0,1); glVertex3f(0.15, 0, 0); glEnd(); glPopMatrix(); /* RIGHT DECAL */ glPushMatrix(); glTranslatef(-8.0, 0.0, 0.0); glTranslatef(0.0, -6.5, 0.0); glTranslatef(0.0, 0.0, 0.20); glRotatef(180, 0.0, 0.0, 1.0); glRotatef(6.35, 1.0, 1.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glRotatef(-25, 0.0, 1.0, 0.0); glBegin(GL_POLYGON); glTexCoord2f(0,0); glVertex3f(0, 0, 0); glTexCoord2f(1,0); glVertex3f(0, 7, 0); glTexCoord2f(1,1); glVertex3f(-2, 7, 0); glTexCoord2f(0,1); glVertex3f(-0.15, 0, 0); glEnd(); glPopMatrix(); /**** DORSAL ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); glRotatef(-90, 0.0, 0.0, 1.0); glTranslatef(-0.5, 0.0, 1.5); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &dorsalControlPoints[3*row][3*col][0]); glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); /**** LEFT DORSAL ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); glRotatef(180, 0.0, 0.0, 1.0); glTranslatef(-0.5, 0.0, 1.5); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &sideDorsalControlPoints[3*row][3*col][0]); glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); /**** RIGHT DORSAL ****/ glPushMatrix(); glRotatef(90, 1.0, 0.0, 0.0); //glRotatef(, 0.0, 0.0, 1.0); glTranslatef(-0.5, 0.0, 1.5); for (row=0; row < 4; row++) { for (col = 0; col < 4; col++) { glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 39, 4, &sideDorsalControlPoints[3*row][3*col][0]); glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); } } glPopMatrix(); glPopMatrix(); /* end airplane stuff */ switchTextures(CLOUD); /**** BACKGROUND ****/ glPushMatrix(); //glRotatef(180, 0.0, 1.0, 0.0); //glRotatef(45.0, 0.0, 1.0, 0.0); glRotatef(-90.0, 1.0, 0.0, 0.0); glTranslatef(0.0, 0.0, -50); //glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &texel[0][0][0]); glBegin(GL_POLYGON); glTexCoord2f(0,0); glVertex3f(-100, -50, 0); glTexCoord2f(1,0); glVertex3f(100, -50, 0); glTexCoord2f(1,1); glVertex3f(100, 50, 0); glTexCoord2f(0,1); glVertex3f(-100, 50, 0); glEnd(); //gluDisk(p, 0, 10.0, 4, 4); glPopMatrix(); glutSwapBuffers(); glDisable(GL_TEXTURE_2D); }
/* The main drawing function. */ void DrawGLScene(void) { const_move(delta.get_ticks()); delta.start(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(-(gridsize/2) +1, 0, -30); //glRotatef(zrot, 0.0f, 0.0f, 1.0f); // choose the texture to use glBindTexture(GL_TEXTURE_2D, texture[0]); //glLoadIdentity(); for(float _xtrans_l =0; _xtrans_l < gridsize; _xtrans_l+=2) { for(float _ztrans_l =0; _ztrans_l < gridsize; _ztrans_l+=2) { //glPushMatrix(); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3ub(144, 213, 225); glLineWidth(1); glPushMatrix(); // rotate triangle on y axis /**glRotatef(xrot, 0.0f, 1.0f, 0.0f);*/ //glRotatef(0, 0.0f, 0.0f, 0.0f); glTranslatef(_xtrans_l, _ytrans, _ztrans_l); if(_xtrans_l != gridsize) { glBegin(GL_LINES); glVertex3f(-1.0f, 0.0f, -1.0f); glVertex3f(1.0f, 0.0f, -1.0f); glEnd(); glBegin(GL_LINES); glVertex3f(-1.0f, 0.0f, 1.0f); glVertex3f(1.0f, 0.0f, 1.0f); glEnd(); } // { // glBegin(GL_LINES); // glVertex3f(0.0f, 0.0f, 0.0f); // glVertex3f(2.0f, 0.0f, 0.0f); // glEnd(); // } if(_ztrans_l != gridsize) { glBegin(GL_LINES); glVertex3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.0f, 0.0f, 1.0f); glEnd(); glBegin(GL_LINES); glVertex3f(1.0f, 0.0f, -1.0f); glVertex3f(1.0f, 0.0f, 1.0f); glEnd(); } // { // glBegin(GL_LINES); // glVertex3f(0.0f, 0.0f, 0.0f); // glVertex3f(0.0f, 0.0f, 2.0f); // glEnd(); // } glPopMatrix(); } } glPushMatrix(); glTranslatef(_xtrans, _ytrans, _ztrans); if(dir_array[0]) { //up glRotatef(90, 0, 1, 0); } else if(dir_array[1]) { //right glRotatef(0, 0, 1, 0); } else if(dir_array[2]) { //down glRotatef(-90, 0, 1, 0); } else if(dir_array[3]) { //left glRotatef(180, 0, 1, 0); } //draw cube for player palceholder glBegin(GL_QUADS); //bottom colour glColor3ub(144, 213, 225); //bottom glVertex3f(-1.0f, 0.0f, -1.0f); glVertex3f(1.0f, 0.0f, -1.0f); glVertex3f(1.0f, 0.0f, 1.0f); glVertex3f(-1.0f, 0.0f, 1.0f); //left colour glColor3ub(144, 213, 225); //left glVertex3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.0f, 0.0f, 1.0f); glVertex3f(-1.0f, 2.0f, 1.0f); glVertex3f(-1.0f, 2.0f, -1.0f); //top colour glColor3ub(144, 213, 225); //top glVertex3f(-1.0f, 2.0f, -1.0f); glVertex3f(-1.0f, 2.0f, 1.0f); glVertex3f(1.0f, 2.0f, 1.0f); glVertex3f(1.0f, 2.0f, -1.0f); //right colour glColor3ub(144, 213, 225); //right bottom glVertex3f(1.0f, 0.0f, -1.0f); glVertex3f(2.0f, 1.0f, -1.0f); glVertex3f(2.0f, 1.0f, 1.0f); glVertex3f(1.0f, 0.0f, 1.0f); //right colour glColor3ub(144, 213, 225); // right top glVertex3f(1.0f, 2.0f, -1.0f); glVertex3f(2.0f, 1.0f, -1.0f); glVertex3f(2.0f, 1.0f, 1.0f); glVertex3f(1.0f, 2.0f, 1.0f); //front colour glColor3ub(144, 213, 225); //front glVertex3f(-1.0f, 0.0f, 1.0f); glVertex3f(1.0f, 0.0f, 1.0f); glVertex3f(1.0f, 2.0f, 1.0f); glVertex3f(-1.0f, 2.0f, 0.0f); //back colour glColor3ub(144, 213, 225); //back glVertex3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.0f, 2.0f, -1.0f); glVertex3f(1.0f, 2.0f, -1.0f); glVertex3f(1.0f, 0.0f, -1.0f); glEnd(); glPopMatrix(); //push mid points of top and bottom of cube into vector // top // int vertexarray[12] = {}; // trail_vector.push_back(); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); //count = 0; float _xtrans_int = _xtrans; if( _xtrans_int > 2) { count ++; _xtrans_int = 0; } std::cout << _xtrans_int << std::endl; for(int i = 0; i < count; i++) { glPushMatrix(); drawtrail(count); glPopMatrix(); } // since this is double buffered, swap the buffers to display what just got drawn. glutSwapBuffers(); }
static void Draw(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glColor3f(.8,0,0); glVertex3f(-0.9, -0.9, -30.0); glColor3f(0,.9,0); glVertex3f( 0.9, -0.9, -30.0); glColor3f(0,0,.7); glVertex3f( 0.0, 0.9, -30.0); glEnd(); glLineWidth(4.0); glBegin(GL_LINES); glColor3f(.1,.7,.1); glVertex3f( 0.5, -0.5, -30.0); glVertex3f( 0.5, 0.5, -30.0); glColor3f(.1,.1,.8); glVertex3f( 0.5, 0.5, -30.0); glVertex3f(-0.5, 0.5, -30.0); glColor3f(.5,.1,.1); glVertex3f(-0.5, 0.5, -30.0); glVertex3f(-0.5, -0.5, -30.0); glColor3f(.8,.8,.8); glVertex3f(-0.5, -0.5, -30.0); glVertex3f( 0.5, -0.5, -30.0); glEnd(); /* glLineWidth(12.0); */ /* Redraw parts of the lines: */ glBegin(GL_LINES); glColor3f(.1,.7,.1); glVertex3f( 0.5, -0.2, -30.0); glVertex3f( 0.5, 0.2, -30.0); glColor3f(.1,.1,.8); glVertex3f( 0.2, 0.5, -30.0); glVertex3f(-0.2, 0.5, -30.0); glColor3f(.5,.1,.1); glVertex3f(-0.5, 0.2, -30.0); glVertex3f(-0.5, -0.2, -30.0); glColor3f(.8,.8,.8); glVertex3f(-0.2, -0.5, -30.0); glVertex3f( 0.2, -0.5, -30.0); glEnd(); glFlush(); if (doubleBuffer) { glutSwapBuffers(); } }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { static CStopWatch timer; // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; glBindTexture(GL_TEXTURE_2D, starTexture); glUseProgram(starFieldShader); glUniformMatrix4fv(locMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locStarTexture, 0); // Draw small stars #ifdef OPENGL_ES glUniform1f(locPointSize, 4.0f); #else glPointSize(4.0f); #endif smallStarBatch.Draw(); // Draw medium sized stars #ifdef OPENGL_ES glUniform1f(locPointSize, 8.0f); #else glPointSize(8.0f); #endif mediumStarBatch.Draw(); // Draw largest stars #ifdef OPENGL_ES glUniform1f(locPointSize, 12.0f); #else glPointSize(12.0f); #endif largeStarBatch.Draw(); // Draw distant horizon shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); glLineWidth(3.5); mountainRangeBatch.Draw(); // Draw the "moon" #ifndef OPENGL_ES glBindTexture(GL_TEXTURE_2D_ARRAY, moonTexture); #endif glUseProgram(moonShader); glUniformMatrix4fv(locMoonMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locMoonTexture, 0); // fTime goes from 0.0 to 28.0 and recycles float fTime = timer.GetElapsedSeconds(); fTime = fmod(fTime, 28.0f); glUniform1f(locTimeStamp, fTime); #ifdef OPENGL_ES glBindTexture(GL_TEXTURE_2D, moonTextures[(int)fTime]); #endif moonBatch.Draw(); // Swap buffers glutSwapBuffers(); glutPostRedisplay(); }
void MultiCursorAppCpp::display(void) { const float divisionX = 12; float cellLength = VEC_WIN_WIDTH[0] / divisionX; glClearColor(1.0, 1.0, 1.0, 1.0); for (size_t i = 0; i < VEC_WIN_WIDTH.size(); ++i) { glutSetWindow(WinIDs[(int)0]); glClear(GL_COLOR_BUFFER_BIT); } if (userData.size() > 0) { for (int i = 0; i < userData.size(); ++i) { if (!userData.empty() && userData[i].cursorInfo.isShownCursor) { // 描画ウィンドウをセット glutSetWindow(WinIDs[userData[i].cursorInfo.displayNum]); int windowWidth = VEC_WIN_WIDTH[userData[i].cursorInfo.displayNum]; int windowHeight = VEC_WIN_HEIGHT[userData[i].cursorInfo.displayNum]; windowWidth = windowWidth; windowHeight = windowHeight; #if 1 // 分割したグリッドでカーソル描画 int posX = (int)(userData[i].cursorInfo.position.x) / (int)(cellLength) * cellLength; int posY = ((int)(windowHeight - userData[i].cursorInfo.position.y) / (int)(cellLength) + 1) * cellLength; float posXGL = ((float)posX - (float)windowWidth / 2) / ((float)windowWidth / 2); float posYGL = ((float)posY - (float)windowHeight / 2) / ((float)windowHeight / 2); float ofX = cellLength / ((float)windowWidth / 2); float ofY = cellLength / ((float)windowHeight / 2); glColor4f(0.1f, 1.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glVertex2f(posXGL, posYGL); glVertex2f(posXGL + ofX, posYGL); glVertex2f(posXGL + ofX, posYGL - ofY); glVertex2f(posXGL, posYGL - ofY); glEnd(); //cout << posXGL << ", " << posYGL << endl; #endif #if 1 // 正確な位置を表すポインタ描画 #ifdef USE_KINECT_V1 Point2f cursorPos((userData[i].cursorInfo.position.x - windowWidth / 2) / windowWidth, -(userData[i].cursorInfo.position.y - windowHeight / 2) / windowHeight); #else Point2f cursorPos((userData[i].cursorInfo.position.x - windowWidth / 2) / windowWidth * 2, (windowHeight - userData[i].cursorInfo.position.y - windowHeight / 2) / windowHeight * 2); #endif glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); float offset = 40; float offsetX = (offset / (float)windowWidth); float offsetY = (offset / (float)windowHeight); glVertex2f(cursorPos.x, cursorPos.y); glVertex2f(cursorPos.x + offsetX, cursorPos.y); glVertex2f(cursorPos.x + offsetX, cursorPos.y + offsetY); glVertex2f(cursorPos.x, cursorPos.y + offsetY); glEnd(); #endif } } } glFlush(); glutSwapBuffers(); }
// DRAW FUNCTION // *********************** void display(void) { // Clear Buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load Modelview glMatrixMode(GL_MODELVIEW); // Set camera direction and position glLoadIdentity(); glcam.LookAt(); // Lighting stuff //GLfloat LightPosition[] = {0.0f,0.0f,10.0f,1.0f}; //GLfloat LightDirection[] = {1.0f, 1.0f, -1.0f}; //glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, LightDirection); // DRAW AXIS POINTS glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); if (axis_num > 0) { glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(PointColor), ((uint8_t*)axis_points+12)); glVertexPointer(3, GL_FLOAT, sizeof(PointColor), ((float*)axis_points)); glDrawArrays(GL_POINTS, 0, axis_num); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); // Fix with IMU GLfloat imumat[16]; imumat[0] = 1.0f; imumat[1] = 0.0f; imumat[2] = 0.0f; imumat[3] = 0.0f; imumat[4] = 0.0f; imumat[5] = 1.0f; imumat[6] = 0.0f; imumat[7] = 0.0f; imumat[8] = 0.0f; imumat[9] = 0.0f; imumat[10] = 1.0f; imumat[11] = 0.0f; imumat[12] = 0.0f; imumat[13] = 0.0f; imumat[14] = 0.0f; imumat[15] = 1.0f; /* double alpha = initial_imu.z; double gamma = initial_imu.x; imumat[0] = cos(alpha); imumat[4] = -sin(alpha)*cos(gamma); imumat[8] = sin(alpha)*sin(gamma); imumat[12] = 0.0f; imumat[1] = sin(alpha); imumat[5] = cos(alpha)*cos(gamma); imumat[9] = -cos(alpha)*sin(gamma); imumat[13] = 0.0f; imumat[2] = 0.0f; imumat[6] = sin(gamma); imumat[10] = cos(gamma); imumat[14] = 0.0f; imumat[3] = 0.0f; imumat[7] = 0.0f; imumat[11] = 0.0f; imumat[15] = 1.0f; */ glMultMatrixf(imumat); glPushMatrix(); // DRAW KEYFRAMES for (unsigned int i = 0; i < keyframes.size(); i++) { // Change Coordinate Frame if (keyframes[i]->global == true) { glPopMatrix(); glPushMatrix(); } GLfloat mat[16]; mat[0] = keyframes[i]->rotation[0]; mat[4] = keyframes[i]->rotation[1]; mat[8] = keyframes[i]->rotation[2]; mat[12] = keyframes[i]->translation[0]; mat[1] = keyframes[i]->rotation[3]; mat[5] = keyframes[i]->rotation[4]; mat[9] = keyframes[i]->rotation[5]; mat[13] = keyframes[i]->translation[1]; mat[2] = keyframes[i]->rotation[6]; mat[6] = keyframes[i]->rotation[7]; mat[10] = keyframes[i]->rotation[8]; mat[14] = keyframes[i]->translation[2]; mat[3] = 0.0f; mat[7] = 0.0f; mat[11] = 0.0f; mat[15] = 1.0f; glMultMatrixf(mat); // Draw Camera Volume if (i == keyframes.size() - 1) { float w = keyframes[i]->im->width; float h = keyframes[i]->im->height; float fx = 519.0f; float fy = 519.0f; float cx = 335.0f; float cy = 267.0f; float z = 1.0f; float x1 = z*(0.0f-cx)/fx; float y1 = z*(0.0f-cy)/fy; float x2 = z*(w-cx)/fx; float y2 = z*(0.0f-cy)/fy; float x3 = z*(w-cx)/fx; float y3 = z*(h-cy)/fy; float x4 = z*(0.0f-cx)/fx; float y4 = z*(h-cy)/fy; glBegin(GL_LINES); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(x1, y1, z); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(x2, y2, z); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(x3, y3, z); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(x4, y4, z); glVertex3f(x1, y1, z); glVertex3f(x2, y2, z); glVertex3f(x2, y2, z); glVertex3f(x3, y3, z); glVertex3f(x3, y3, z); glVertex3f(x4, y4, z); glVertex3f(x4, y4, z); glVertex3f(x1, y1, z); glEnd(); } // Draw 3-Axis Thing glBegin(GL_LINES); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.1f, 0.0f, 0.0f); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.1f, 0.0f); glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.1f); glEnd(); // Draw Points glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); if (keyframes[i]->numberOf3DPoints > 0) { glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(PointColor), ((uint8_t*)keyframes[i]->points+12)); glVertexPointer(3, GL_FLOAT, sizeof(PointColor), ((float*)keyframes[i]->points)); glDrawArrays(GL_POINTS, 0, keyframes[i]->numberOf3DPoints); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); // Draw Matched Features /*for (int j = 0; j < keyframes[i]->features.size(); j++) { glPushMatrix(); if (i%3 == 0) glColor4f(1.0f, 0.0f, 0.0f, 1.0f); else if (i%3 == 1) glColor4f(0.0f, 1.0f, 0.0f, 1.0f); else glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glTranslatef(keyframes[i]->features[j].point3D[0], keyframes[i]->features[j].point3D[1], keyframes[i]->features[j].point3D[2]); // x,y,z glBegin(GL_POINTS); glutWireSphere(0.01, 6, 6); glEnd( ); glPopMatrix(); }*/ } glPopMatrix(); // Swap buffers glutSwapBuffers(); }
void INIT(void) { printf("Morph 3D - Shows morphing platonic polyhedra\n"); printf("Author: Marcelo Fernandes Vianna ([email protected])\n\n"); printf(" [1] - Tetrahedron\n"); printf(" [2] - Hexahedron (Cube)\n"); printf(" [3] - Octahedron\n"); printf(" [4] - Dodecahedron\n"); printf(" [5] - Icosahedron\n"); printf(" [s] - Slow, more sleep time\n"); printf(" [f] - Faster,less sleep time\n"); printf("[SPACE] - Toggle colored faces\n"); printf("[RETURN] - Toggle smooth/flat shading\n"); printf(" [ESC] - Quit\n"); object=1; glutInitWindowPosition(0,0); glutInitWindowSize(640,480); glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB ); if (glutCreateWindow("Morph 3D - Shows morphing platonic polyhedra") <= 0) { exit(0); } glClearDepth(1.0); glClearColor( 0.0, 0.0, 0.0, 1.0 ); glColor3f( 1.0, 1.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glFlush(); glutSwapBuffers(); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position0); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_POSITION, position1); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); glHint(GL_FOG_HINT, GL_FASTEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); pinit(); glutReshapeFunc( reshape ); glutKeyboardFunc( key ); glutIdleFunc( idle_ ); glutDisplayFunc( draw ); glutMainLoop(); }
/* Handler for window-repaint event. Called back when the window first appears and whenever the window needs to be re-painted. */ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix // Render a color-cube consisting of 6 quads with different colors glLoadIdentity(); // Reset the model-view matrix glTranslatef(1.5f, 0.0f, -7.0f); // Move right and into the screen glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads // Top face (y = 1.0f) // Define vertices in counter-clockwise (CCW) order with normal pointing out glColor3f(0.0f, 1.0f, 0.0f); // Green glVertex3f( 1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom face (y = -1.0f) glColor3f(1.0f, 0.5f, 0.0f); // Orange glVertex3f( 1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Front face (z = 1.0f) glColor3f(1.0f, 0.0f, 0.0f); // Red glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Back face (z = -1.0f) glColor3f(1.0f, 1.0f, 0.0f); // Yellow glVertex3f( 1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Left face (x = -1.0f) glColor3f(0.0f, 0.0f, 1.0f); // Blue glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face (x = 1.0f) glColor3f(1.0f, 0.0f, 1.0f); // Magenta glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glEnd(); // End of drawing color-cube // Render a pyramid consists of 4 triangles glLoadIdentity(); // Reset the model-view matrix glTranslatef(-1.5f, 0.0f, -6.0f); // Move left and into the screen glBegin(GL_TRIANGLES); // Begin drawing the pyramid with 4 triangles // Front glColor3f(1.0f, 0.0f, 0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); // Green glVertex3f(-1.0f, -1.0f, 1.0f); glColor3f(0.0f, 0.0f, 1.0f); // Blue glVertex3f(1.0f, -1.0f, 1.0f); // Right glColor3f(1.0f, 0.0f, 0.0f); // Red glVertex3f(0.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.0f, 1.0f); // Blue glVertex3f(1.0f, -1.0f, 1.0f); glColor3f(0.0f, 1.0f, 0.0f); // Green glVertex3f(1.0f, -1.0f, -1.0f); // Back glColor3f(1.0f, 0.0f, 0.0f); // Red glVertex3f(0.0f, 1.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); // Green glVertex3f(1.0f, -1.0f, -1.0f); glColor3f(0.0f, 0.0f, 1.0f); // Blue glVertex3f(-1.0f, -1.0f, -1.0f); // Left glColor3f(1.0f,0.0f,0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,0.0f,1.0f); // Blue glVertex3f(-1.0f,-1.0f,-1.0f); glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f(-1.0f,-1.0f, 1.0f); glEnd(); // Done drawing the pyramid glutSwapBuffers(); // Swap the front and back frame buffers (double buffering) }