void drawLightsMap(){ // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL); // glBlendFunc(GL_SRC_ALPHA,GL_ONE); // glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); glBlendFunc(GL_SRC_ALPHA,GL_SRC_ALPHA); /* if (config.options.darkness.tex_size>128){ setTexture(&config.map.tex[DARKNESS]); Begin(GL_TRIANGLE_FAN); TexCoord2f (config.global.screen.coord.ld.x/scale,config.global.screen.coord.ld.y/scale); Vertex2f(config.global.screen.coord.ld.x,config.global.screen.coord.ld.y); TexCoord2f(config.global.screen.coord.lu.x/scale,config.global.screen.coord.lu.y/scale); Vertex2f(config.global.screen.coord.lu.x,config.global.screen.coord.lu.y); TexCoord2f(config.global.screen.coord.ru.x/scale,config.global.screen.coord.ru.y/scale); Vertex2f(config.global.screen.coord.ru.x,config.global.screen.coord.ru.y); TexCoord2f(config.global.screen.coord.rd.x/scale,config.global.screen.coord.rd.y/scale); Vertex2f(config.global.screen.coord.rd.x,config.global.screen.coord.rd.y); End(); } */ drawLights(drawLight); // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); }
void TransparencyRenderer::draw(Scene & scene, Camera & camera) { stateManager.setRenderingStage(StateManager::TRANSPARENCY_STAGE); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Bind Framebuffer checkGLErrors("Binding framebuffer"); checkFramebufferStatus(); // Check that framebuffer config OK shaderManager.bindStageShader(); // Bind Transparency stage shaders glDisable(GL_BLEND); // Enable blending glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set blend func for optimized Transparency rendering glEnable(GL_CULL_FACE); // Disable face culling glEnable(GL_DEPTH_TEST); // Disable Z-Buffer glDisable(GL_TEXTURE_2D); // Disable textures //camera.setGLModelView(); //camera.setGLProjection(); //camera.calculatePlanes(); // Will later be used for culling scene.sortEntities(camera); // Sort entities by depth drawLights(scene,camera); glDisable(GL_BLEND); }
void idGLDrawableView::draw(int x, int y, int w, int h) { int i; renderView_t refdef; const idMaterial *mat = material; if (mat) { qglViewport(x, y, w, h); qglScissor(x, y, w, h); qglMatrixMode(GL_PROJECTION); qglClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); qglClear(GL_COLOR_BUFFER_BIT); UpdateLights(); // render it renderSystem->BeginFrame(w, h); memset( &refdef, 0, sizeof( refdef ) ); UpdateCamera( &refdef ); // Copy global shaderparms to view for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) { refdef.shaderParms[ i ] = globalParms[ i ]; } refdef.width = SCREEN_WIDTH; refdef.height = SCREEN_HEIGHT; refdef.fov_x = 90; refdef.fov_y = 2 * atan((float)h / w) * idMath::M_RAD2DEG; refdef.time = eventLoop->Milliseconds(); world->RenderScene( &refdef ); if ( showLights ) { drawLights( &refdef ); } renderSystem->EndFrame( NULL, NULL ); world->DebugClearLines( refdef.time ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); } }
/* Fonction qui affiche les objets 3D : plan et/ou (sweep/revolution objet, teapot) Appelee chaque fois que la fenetre du viewer doit etre rafraiche. */ void displayViewerWindow() { /* ** AJOUTER CODE ICI ** ** Cette fonction est appelee a chaque fois que le contexte OpenGL est a rafraichir ** ** -Effacer l'ancien contenu (glClear) ** -Activer la pile GL_PROJECTION et preciser les parametres de projection (gluPerspective + gCam) ** -Activer la pile GL_MODELVIEW et positionner la camera (setCamera) ** -Afficher les lumieres (setLighting + drawLights) ** -Afficher le sol (avec setMaterial + drawPlane()) ** -Afficher l'objet (avec setMaterial +drawObject()) ** */ /* Effacer l'ancien contenu */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Configurer une camera (projection perspective) */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(gCam.fovy, gCam.ratio, gCam.znear, gCam.zfar); /* Positionner la camera */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); setCamera(); /* Afficher les lumieres */ drawLights(); /* Afficher le plan avec le gMaterials[0] */ setMaterial(gMaterials[0]); drawPlane(objectResolution, drawNormals); /* Afficher l'objet avec le gMaterials[1] */ setMaterial(gMaterials[1]); drawObject(); glutSwapBuffers(); }
void PerPixelRenderer::render(Renderable& rend) { if(_released) { DefaultRenderer::render(rend); return; } glEnable(GL_TEXTURE_2D); //render shadow map glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_PROJECTION); glPushMatrix(); for(int i=0; i<MAX_LIGHTS; i++) if(glIsEnabled(GL_LIGHT0+i)) { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,_fboId[i]); glViewport(0,0,_w*_shadowRatio,_h*_shadowRatio); setupMatrices(i); setTextureMatrix(i); glCullFace(GL_FRONT); beforeShadowDraw(i); rend.drawObject(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); afterShadowDraw(i); } glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); //render scene glViewport(0,0,_w,_h); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(_showLight)drawLights(); if(_shaderDraw)_shaderDraw->begin(); beforeShadowRender(_shaderDraw); glCullFace(GL_BACK); rend.drawObject(); if(_shaderDraw)_shaderDraw->end(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(spin, 0, 1, 0); aimLights(); setLights(); glPushMatrix(); glRotatef(-90.0, 1, 0, 0); glScalef(1.9, 1.9, 1.0); glTranslatef(-0.5, -0.5, 0.0); drawPlane(16, 16); glPopMatrix(); drawLights(); glPopMatrix(); glutSwapBuffers(); }
void DebuggingView::draw() { if (!valid()) { glShadeModel( GL_SMOOTH ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); glEnable( GL_NORMALIZE ); } glViewport( 0, 0, w(), h() ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,-float(w())/float(h()),1.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_camera->applyViewingTransform(); // Need to apply an extra transform so that our camera 'approximately' // lines up with the scene camera, initially, and to correct for our // definition of "up." { Vec3d uAxis = raytracer->getScene().getCamera().getU(); Vec3d vAxis = raytracer->getScene().getCamera().getV(); Vec3d wAxis = uAxis ^ vAxis; uAxis = wAxis ^ vAxis; uAxis.normalize(); vAxis.normalize(); wAxis.normalize(); GLdouble rotMat[16]; rotMat[0] = uAxis[0]; rotMat[1] = vAxis[0]; rotMat[2] = wAxis[0]; rotMat[3] = 0.0; rotMat[4] = uAxis[1]; rotMat[5] = vAxis[1]; rotMat[6] = wAxis[1]; rotMat[7] = 0.0; rotMat[8] = uAxis[2]; rotMat[9] = vAxis[2]; rotMat[10] = wAxis[2]; rotMat[11] = 0.0; rotMat[12] = 0.0; rotMat[13] = 0.0; rotMat[14] = 0.0; rotMat[15] = 1.0; glMultMatrixd( rotMat ); } if( m_showAxes ) drawAxes(); if( raytracer == 0 || !raytracer->sceneLoaded() ) return; if( m_showLights ) drawLights(); if( m_showGeometry ) { lightScene(); drawScene(); } drawRays(); if( m_showCamera ) drawCamera(); }
void renderScene(void) { GLint loc; FrameCount++; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // load identity matrices loadIdentity(VIEW); loadIdentity(MODEL); float carX = car.getPosition().getX(); float carZ = car.getPosition().getZ(); Vector3 dir = car.getDirection() + car.getPosition(); float dirX = dir.getX(); float dirZ = dir.getZ(); Vector3 cam = car.getPosition() - car.getDirection(); float cX = cam.getX(); float cZ = cam.getZ(); //if (_current_camera == 2) lookAt(cX, 2, cZ, dirX, 1, dirZ, 0, 1, 0); if (_current_camera == 2) { if (clicking) { lookAt(carX, 3, carZ, carX + camX, 1, carZ + camZ, 0, 1, 0); } else { lookAt(cX, 2, cZ, dirX, 1, dirZ, 0, 1, 0); } } else lookAt(0, 10, 0.1, 0, 0, 0, 0, 1, 0); // use our shader glUseProgram(shader.getProgramIndex()); //send the light position in eye coordinates //glUniform4fv(lPos_uniformId, 1, lightPos); //efeito capacete do mineiro, ou seja lighPos foi definido em eye coord _spotLights[0]->setPosition(car.getPosition().getX() + (0.1f * car.getDirection().getX()), car.getPosition().getY() + 1.0f, car.getPosition().getZ() + (0.1f * car.getDirection().getZ()), 1.0f); _spotLights[1]->setPosition(car.getPosition().getX() + (0.1f * car.getDirection().getX()), car.getPosition().getY() + 1.0f, car.getPosition().getZ() + (0.1f * car.getDirection().getZ()), 1.0f); //LIGHTS drawLights(); //Associar os Texture Units aos Objects Texture //stone.tga loaded in TU0; checker.tga loaded in TU1; lightwood.tga loaded in TU2 //Indicar aos tres samplers do GLSL quais os Texture Units a serem usados glUniform1i(tex_loc1, 0); glUniform1i(tex_loc2, 1); for (int i = 0; i < 128; i++) { cheerioArray[i].draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); } car.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); butter2.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); butter1.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); glEnable(GL_STENCIL_TEST); // Draw floor glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilMask(0xFF); // Write to stencil buffer glDepthMask(GL_FALSE); // Don't write to depth buffer glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default) table.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); // Draw cube reflection glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1 glStencilMask(0x00); // Don't write anything to stencil buffer glDepthMask(GL_TRUE); // Write to depth buffer glUniform1i(darken_uniformId, true); butter1ref.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); butter2ref.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); glUniform1i(darken_uniformId, false); glDisable(GL_STENCIL_TEST); for (int i = 0; i < orangeArray.size(); i++) { if (!orangeArray[i].getDelayDraw()) { orangeArray[i].draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); } } glUniform1i(texMode_uniformId, true); road.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); glUniform1i(texMode_uniformId, false); drawBroccoli(); glUniform1i(lightsOff_uniformId, true); glUniform1i(texMode_uniformId, true); sun.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); glUniform1i(texMode_uniformId, false); glUniform1i(lightsOff_uniformId, false); if (fireworks) { glUniform1i(texMode_uniformId, true); glUniform1i(lightsOff_uniformId, true); particles.render(textureArray[5], mesh[11], vm_uniformId, pvm_uniformId, normal_uniformId, shader, car.getAngle() - 180); glUniform1i(texMode_uniformId, false); glUniform1i(lightsOff_uniformId, false); } cup.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); FLARE_DEF renderFlare; renderFlare.fScale = 1; renderFlare.fMaxSize = 1.0; renderFlare.nPieces = 4; renderFlare.element[0].texture = &textureArray[6]; renderFlare.element[0].fDistance = 0; renderFlare.element[0].fSize = 1.0; renderFlare.element[0].argb = 0xff6060ff; renderFlare.element[1].texture = &textureArray[7]; renderFlare.element[1].fDistance = 1.0; renderFlare.element[1].fSize = 1.0; renderFlare.element[1].argb = 0xff6060ff; renderFlare.element[2].texture = &textureArray[8]; renderFlare.element[2].fDistance = 2.0; renderFlare.element[2].fSize = 1.0; renderFlare.element[2].argb = 0xff6060ff; renderFlare.element[3].texture = &textureArray[9]; renderFlare.element[3].fDistance = 3.0; renderFlare.element[3].fSize = 1.0; renderFlare.element[3].argb = 0xff6060ff; float sunp[4] = { sun.getPosition().getX(), sun.getPosition().getY(), sun.getPosition().getZ(), 1.0f }; float view[16]; float projection[16]; double viewd[16]; double projd[16]; double winx, winy, winz; int viewp[4]; memcpy(view, mMatrix[VIEW], 16 * sizeof(float)); memcpy(projection, mMatrix[PROJECTION], 16 * sizeof(float)); for (int i = 0; i < 16; i++) { viewd[i] = (double)view[i]; projd[i] = (double)projection[i]; } glGetIntegerv(GL_VIEWPORT, viewp); gluProject(sunp[0], sunp[1], sunp[2], viewd, projd, viewp, &winx, &winy, &winz); float sun_pos_x = winx; float sun_pos_y = winy; if (sun_pos_y <= 400) sun_pos_y = -500; //HUD stuff float ratio = (1.0f * glutGet(GLUT_WINDOW_WIDTH)) / glutGet(GLUT_WINDOW_HEIGHT); pushMatrix(PROJECTION); // Save the current matrix loadIdentity(PROJECTION); // We initialize the projection matrix as identity _hudCamera->update(ratio); pushMatrix(VIEW); // Save the current matrix loadIdentity(VIEW); // Initialize the model matrix as identity glUniform1i(lightsOff_uniformId, true); glUniform1i(texMode_uniformId, true); if (70 < car.getAngle() && car.getAngle() < 230 && _current_camera == 2) { flare.render(&renderFlare, sun_pos_x, sun_pos_y, glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2, shader, mesh[11], pvm_uniformId, vm_uniformId, normal_uniformId); } glUniform1i(texMode_uniformId, false); glUniform1i(lightsOff_uniformId, false); if (paused) { glDepthMask(GL_FALSE); glUniform1i(lightsOff_uniformId, true); glUniform1i(texMode_uniformId, true); if (remainingLives > 0) { pauseScreen.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); } else { deathScreen.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); } glUniform1i(lightsOff_uniformId, false); glUniform1i(texMode_uniformId, false); glDepthMask(GL_TRUE); } glUniform1i(lightsOff_uniformId, true); HUDbg.draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); for (int i = 0; i < remainingLives; i++) { _lives.at(i)->draw(shader, pvm_uniformId, vm_uniformId, normal_uniformId); } glUniform1i(lightsOff_uniformId, false); popMatrix(VIEW); // Restore the previous matrix popMatrix(PROJECTION); // Restore the previous matrix glBindTexture(GL_TEXTURE_2D, 0); glutSwapBuffers(); }