void SceneToon::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); vec4 lightPos = vec4(10.0f * cos(angle), 10.0f, 10.0f * sin(angle), 1.0f); prog.setUniform("Light.position", view * lightPos); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,0.0f,-2.0f)); model *= glm::rotate(45.0f, vec3(0.0f,1.0f,0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); model = mat4(1.0f); model *= glm::translate(vec3(-1.0f,0.75f,3.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); torus->render(); prog.setUniform("Kd", 0.7f, 0.7f, 0.7f); prog.setUniform("Ka", 0.2f, 0.2f, 0.2f); model = mat4(1.0f); setMatrices(); plane->render(); }
DistanceAccumulator::DistanceAccumulator() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _nearFarRatio(0.0005), _maxDepth(UINT_MAX) { setMatrices(osg::Matrix::identity(), osg::Matrix::identity()); reset(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setMatrices(); cube->render(); }
CURRENT_CLASS::CURRENT_CLASS() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _nearFarRatio(0.0005), _maxDepth( UINT_MAX) { setMatrices(osg::Matrix::identity(),osg::Matrix::identity()); reset(); }
void renderFrame() { // Always clear the frame buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int shaderNum; // Cathedral scene (scene1, meshes_1, shader 0) cur_scene = scene1; currentMesh_vec = &meshes_1; shaderNum = 0; for (int i = 0; i < currentMesh_vec->size(); i++) { glUseProgram(shaders[shaderNum]->programID()); setMatrices(cur_scene); setMaterial(cur_scene, i, shaderNum); setTextures(i, shaderNum, false); setMeshData(i, shaderNum); // Draw the mesh if ((*currentMesh_vec)[i].mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) { glDrawElements(GL_TRIANGLES, 3*(*currentMesh_vec)[i].mesh->mNumFaces, GL_UNSIGNED_INT, &(*currentMesh_vec)[i].indexBuffer[0]); } } // Statue scene (scene2, meshes_2, shader 1) cur_scene = scene2; currentMesh_vec = &meshes_2; shaderNum = 1; for (int i = 0; i < currentMesh_vec->size(); i++) { glUseProgram(shaders[shaderNum]->programID()); setMatrices(cur_scene); setMaterial(cur_scene, i, shaderNum); setTextures(i, shaderNum, false); setMeshData(i, shaderNum); // Draw the mesh if ((*currentMesh_vec)[i].mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) { glDrawElements(GL_TRIANGLES, 3*(*currentMesh_vec)[i].mesh->mNumFaces, GL_UNSIGNED_INT, &(*currentMesh_vec)[i].indexBuffer[0]); } } }
bool UCamPar::setPixelSize(float pixSize) { bool result; // resFactor = pixSize; // recalculate conversion matrices result = setMatrices(); // return result; }
void ArcShaderProgram::run(ArcCanvas &canvas, ArcMatrix model, ArcMatrix view) { glUseProgram(mProgram); ExitOnGLError("ERROR: Could not use the shader program"); setMatrices(model, view); canvas.draw(); glUseProgram(0); }
void SceneADS::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //model = mat4(1.0f); //model *= glm::rotate(model, angle, vec3(0.0f,1.0f,0.0f)); //model *= glm::rotate(model, -35.0f, vec3(1.0f,0.0f,0.0f)); //model *= glm::rotate(model, 35.0f, vec3(0.0f,1.0f,0.0f)); setMatrices(); torus->render(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLuint programHandle = prog.getHandle(); GLuint adsIndex = glGetSubroutineIndex( programHandle, GL_VERTEX_SHADER, "phongModel" ); GLuint diffuseIndex = glGetSubroutineIndex(programHandle, GL_VERTEX_SHADER, "diffuseOnly"); glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &adsIndex); model = mat4(1.0f); model *= glm::translate(vec3(-3.0f,-1.5f,0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &diffuseIndex); model = mat4(1.0f); model *= glm::translate(vec3(3.0f,-1.5f, 0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); }
bool UCamPar::setCameraParameters(float hx, float hy, float k1, float k2, float focalLng, float pixSizeFactor) { headX = hx; headY = hy; radialK1 = k1; radialK2 = k2; focalLength = focalLng; resFactor = pixSizeFactor; parValid = setMatrices(); // return parValid; }
void SceneRenderToTex::renderToTexture() { prog.setUniform("RenderTex", 1); glViewport(0,0,512,512); glClearColor(0.5f, 0.5f, 0.5f, 1.0f ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); view = glm::lookAt(vec3(0.0f,0.0f,7.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f)); projection = glm::perspective(60.0f, 1.0f, 0.3f, 100.0f); prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f) ); prog.setUniform("Light.Intensity", vec3(1.0f,1.0f,1.0f) ); prog.setUniform("Material.Kd", 0.9f, 0.9f, 0.9f); prog.setUniform("Material.Ks", 0.95f, 0.95f, 0.95f); prog.setUniform("Material.Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Material.Shininess", 100.0f); model = mat4(1.0f); model = glm::translate(model, vec3(0.0f,-1.5f,0.0f)); model = glm::rotate(model, -90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); }
void SceneRenderToTex::renderScene() { prog.setUniform("RenderTex", 0); glViewport(0,0,width,height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); vec3 cameraPos = vec3(2.0f * cos(angle), 1.5f, 2.0f * sin(angle)); view = glm::lookAt(cameraPos, vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f)); projection = glm::perspective(45.0f, (float)width/height, 0.3f, 100.0f); prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f) ); prog.setUniform("Light.Intensity", vec3(1.0f,1.0f,1.0f) ); prog.setUniform("Material.Kd", 0.9f, 0.9f, 0.9f); prog.setUniform("Material.Ks", 0.95f, 0.95f, 0.95f); prog.setUniform("Material.Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Material.Shininess", 100.0f); model = mat4(1.0f); setMatrices(); cube->render(); }
void AppGLContext::update(float dt) { static float eye_x = 0.0f, eye_z = 0.0f; static float time = 0.0f; time += dt; eye_x = 1.0f*cosf(0.25f*time); eye_z = 1.0f*sinf(0.25f*time); view = glm::lookAt(vec3(eye_x,0.5f,eye_z), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f)); float a = aquaSurf->getWaveAmplitude(0); float w = aquaSurf->getWaveFrequency(0); float ph = aquaSurf->getWavePhase(0); dolphinWorld[3][1] = a*sinf(time*w + ph); setMatrices(); if( aquaSurf ) { aquaSurf->update(dt); } }
void TileRender::setMatricesWindowPersp( int screenWidth, int screenHeight, float fovDegrees, float nearPlane, float farPlane ) { CameraPersp cam( screenWidth, screenHeight, fovDegrees, nearPlane, farPlane ); setMatrices( cam ); }
void renderFrame() { ////////////////////////////////////////////////////////////////////////// // TODO: ADD YOUR RENDERING CODE HERE. You may use as many .cpp files // in this assignment as you wish. ////////////////////////////////////////////////////////////////////////// // Move the player based on keyboard input (wasd) move(); // Move the light based on keyboard input (arrows) updateLightPosition(); // Generate a shadow map, and send the light matrix over to the shader in texture matrix 7 depthRenderTarget->bind(); glUseProgram(simpleShader->programID()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setLightMatrix(); renderNode(simpleShader, cathedralScene, cathedralScene->mRootNode, true); renderNode(simpleShader, armadilloScene, armadilloScene->mRootNode, true); depthRenderTarget->unbind(); // Render our scene, sending the model matrices over to the shader in texture matrix 6 glUseProgram(phongShader->programID()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setMatrices(); renderNode(phongShader, cathedralScene, cathedralScene->mRootNode, true); // Render the armadillo using the environment map shader. glUseProgram(envMapShader->programID()); setMatrices(); renderNode(envMapShader, armadilloScene, armadilloScene->mRootNode, true); // Display a test quad on screen (press t key to toggle) if (test) { // Render test quad glDisable(GL_LIGHTING); glUseProgramObjectARB(0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-RENDER_WIDTH/2,RENDER_WIDTH/2,-RENDER_HEIGHT/2,RENDER_HEIGHT/2,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1,1,1,1); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, depthRenderTarget->textureID()); glEnable(GL_TEXTURE_2D); glTranslated(0,-RENDER_HEIGHT/2,-1); glBegin(GL_QUADS); glTexCoord2d(0,0); glVertex3f(0,0,0); glTexCoord2d(1,0); glVertex3f(RENDER_WIDTH/2,0,0); glTexCoord2d(1,1); glVertex3f(RENDER_WIDTH/2,RENDER_HEIGHT/2,0); glTexCoord2d(0,1); glVertex3f(0,RENDER_HEIGHT/2,0); glEnd(); glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); depthRenderTarget->unbind(); } }
void GLWidget::paintGL() { //si se esta generando un mallado no podemos recorrer o representar ningun mallado ya que algun algoritmo está escribiendo en el vector de pixels if (generatingMesh) return; if (mesh == NULL); glViewport(0.0, 0.0, width(), height()); glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); setMatrices(); drawBackground(); //Rotar, girar y escalar la figura glTranslatef((mesh->width / 2), (mesh->height / 2 - yMove), -(510.0f) + zMove); glRotatef(xRot, 1, 0, 0); glTranslatef(-(mesh->width / 2 - xMove), -(mesh->height / 2), 0.0f); glTranslatef((mesh->width / 2), (mesh->height / 2), 0.0f); glRotatef(yRot, 0, 0, 1); glTranslatef(-(mesh->width / 2), -(mesh->height / 2), 0.0f - (mesh->frames / 2)); //If you copy all these position in the lines before the rotations (after draw background), the lights will rotate with the camera (like if you are holding a flashlight). not with the mesh //Position of light 1 float lightPosition[4] = { 0, 0, 0, 1 }; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); //Position of light 2 float lightPosition1[4] = { mesh->width, mesh->height / 8, 0, 1 }; glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1); //Position of light 3 float lightPosition2[4] = { mesh->width / 2, mesh->height / 1.1, 0, 1 }; glLightfv(GL_LIGHT2, GL_POSITION, lightPosition2); float lightPosition3[4] = { mesh->width / 2, mesh->height / 1.1, 0, 0 }; glLightfv(GL_LIGHT3, GL_POSITION, lightPosition3); //Dibujar la figura secundaria primero ya que la primaria se tiene que dibujar después para que transparente sobre la otra glColor4f(1.0f, 0.9f, 0.65f, 1.0f); if (showMesh) drawMesh(mesh2); glColor4f(0.55f, 0.55f, 0.55f,float (opacity)); if (showMesh) drawMesh(mesh); glColor3f(1.f, 0.f, 0.f); if (showGradients) displayGradient(); if (showWireframe){ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(1.5f); glColor3f(1.f, 0.f, 0.f); drawMesh(mesh); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } else{ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } }
void Light::setShadowRenderMatrices() const { setMatrices( mShadowCam ); }