void BSPLoader::renderNode( int index ) { if (index < 0 || index >= _nodes.size()) { return; } sBSPNode node = _nodes[index]; if (node.children[0] < 0) { renderFace(-1 - node.children[0]); } else { renderNode(node.children[0]); } if (node.children[1] < 0) { renderFace(-1 - node.children[1]); } else { renderNode(node.children[1]); } }
// this function actually renders the model at place (x, y, z) and then rotated around the y axis by 'angle' degrees void Model::RenderModel() { //glEnable(GL_CULL_FACE); //glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); if(file->lights) //if we have lights in the model { EnableLights(); //enable all lights glCallList(lightListIndex); //set lights. } ///cout << "B"; Lib3dsNode *nodes; for(nodes = file->nodes;nodes != 0;nodes = nodes->next)// Render all nodes { renderNode(nodes); //cout << "R"; } if(file->lights) DisableLights(); // disable lighting, we don't want it have it enabled longer than necessary curFrame++; if(curFrame > file->frames) //if the next frame doesn't exist, go to frame 0 curFrame = 0; lib3ds_file_eval(file, curFrame); // set current frame //glDisable(GL_CULL_FACE); glShadeModel(GL_FLAT); }
void MapState::renderNode(NodeData* node) { while(node != nullptr) { if(node->complete) sp_dot.setScale(2.0, 2.0); else sp_dot.setScale(1.0, 1.0); if(node->selected) sp_dot.setColor(sf::Color(255,0,0) ); else sp_dot.setColor(sf::Color(255,255,255) ); sp_dot.setPosition(node->pos); window.draw(sp_dot); node->visible = true; if( node->complete ){ for(auto item : node->adjacent) { //cout << "Render: " << node->pos.x << " " << node->adjacent.size() << endl; renderNode(item); } } node = nullptr; } }
void TimingProfiler::renderNode( TimingProfileNode* nodeToRender, const float FONT_SIZE, Vector2& startLocation, Vector2& startLocationCurrent, Vector2& startLocationAverage, Vector2& currentOffset ) { char buffer[ 100 ]; sprintf( buffer, "%s", nodeToRender->m_Name.c_str() ); getTheTextRenderer().addTextToBeRendered( buffer, startLocation + currentOffset, RGBA_WHITE ); memset( buffer, 0, 100 ); PrintTimeToBuffer( buffer, nodeToRender->calculateCurrentTotalTime() ); getTheTextRenderer().addTextToBeRendered( buffer, startLocationCurrent + currentOffset, RGBA_WHITE ); PrintTimeToBuffer( buffer, nodeToRender->calculateAverageTotalTime() ); getTheTextRenderer().addTextToBeRendered( buffer, startLocationAverage + currentOffset, RGBA_WHITE ); currentOffset.y -= int( FONT_SIZE ); startLocation.x += 20; startLocationAverage.x += 20; startLocationCurrent.x += 20; for( auto iter = nodeToRender->m_Children.begin(); iter != nodeToRender->m_Children.end(); ++iter ) { renderNode( *iter, FONT_SIZE, startLocation, startLocationCurrent, startLocationAverage, currentOffset ); } startLocation.x -= 20; startLocationAverage.x -= 20; startLocationCurrent.x -= 20; }
void MapState::render() { window.draw(sp_map); auto startNode = nodes[0]; renderNode(startNode); }
void microRasterize(IntegratorT& integrator, V3f P, V3f N, float coneAngle, float maxSolidAngle, const PointOctree& points) { float cosConeAngle = cos(coneAngle); float sinConeAngle = sin(coneAngle); renderNode(integrator, P, N, cosConeAngle, sinConeAngle, maxSolidAngle, points.dataSize(), points.root()); }
//render- renders the tree //frustum- the frustum to use for culling //deviceContext- the device context to use for rendering //shader- the shader to use for rendering void TerrainQuadTree::render(Frustum* frustum, ID3D11DeviceContext* deviceContext, Shader* shader) { //reset the number of trianglles that are drawn this fram. m_drawCount = 0; //Render eash node that is visable starting at the parent node and moving down the tree. renderNode(m_parentNode,frustum, deviceContext, shader); }
//renderNode- renders the passed in node //frustum- the frustum to use for culling //deviceContext- the device context to use for renering //shader- the shader to use for rendering void TerrainQuadTree::renderNode(Node* node, Frustum* frustum, ID3D11DeviceContext* deviceContext, Shader* shader) { bool result; int count, i, indexCount; unsigned int stride, offset; // Check to see if the node can be viewed, height doesn't matter in a quad tree. result = frustum->checkCube(node->positionX, 0.0f, node->positionZ, (node->width / 2.0f)); // If it can't be seen then none of its children can either so don't continue down the tree, this is where the speed is gained. if (!result) { return; } // If it can be seen then check all four child nodes to see if they can also be seen. count = 0; for (i = 0; i<4; i++) { if (node->nodes[i] != 0) { count++; renderNode(node->nodes[i], frustum, deviceContext, shader); } } // If there were any children nodes then there is no need to continue as parent nodes won't contain any triangles to render. if (count != 0) { return; } // Otherwise if this node can be seen and has triangles in it then render these triangles. // Set vertex buffer stride and offset. stride = sizeof(Vertex); offset = 0; // Set the vertex buffer to active in the input assembler so it can be rendered. deviceContext->IASetVertexBuffers(0, 1, &node->vertexBuffer, &stride, &offset); // Set the index buffer to active in the input assembler so it can be rendered. deviceContext->IASetIndexBuffer(node->indexBuffer, DXGI_FORMAT_R32_UINT, 0); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // Determine the number of indices in this node. indexCount = node->triangleCount * 3; // Call the terrain shader to render the polygons in this node. shader->renderTerrainShader(deviceContext, indexCount); // Increase the count of the number of polygons that have been rendered during this frame. m_drawCount += node->triangleCount; }
void IRenderSystem::endRender() { for ( ; mNextRenderNode != mRenderList.end(); ++mNextRenderNode ) { RNODE& node = *mNextRenderNode; renderNode( node ); } postRender(); }
void RenderNodeVisitor::visit( const NodeId& nodeId, VisitState& state ) { dash::NodePtr node = _impl->getDashNode( nodeId ); if( !node) return; DashRenderNode renderNode( node ); visit( renderNode, state ); }
QRegion QSGAbstractSoftwareRenderer::renderNodes(QPainter *painter) { QRegion dirtyRegion; // If there are no nodes, do nothing if (m_renderableNodes.isEmpty()) return dirtyRegion; auto iterator = m_renderableNodes.begin(); // First node is the background and needs to painted without blending auto backgroundNode = *iterator; dirtyRegion += backgroundNode->renderNode(painter, /*force opaque painting*/ true); iterator++; for (; iterator != m_renderableNodes.end(); ++iterator) { auto node = *iterator; dirtyRegion += node->renderNode(painter); } return dirtyRegion; }
void IRenderSystem::setCurOrder( int order ) { assert( order > mCurOrder ); for ( ; mNextRenderNode != mRenderList.end(); ++mNextRenderNode ) { RNODE& node = *mNextRenderNode; if ( node.obj->getOrder() > order ) break; renderNode( node ); } mCurOrder = order; }
void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; clearValues[0].color = { { 1.0f, 1.0f, 1.0f, 1.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.extent.width = width; renderPassBeginInfo.renderArea.extent.height = height; renderPassBeginInfo.clearValueCount = 2; renderPassBeginInfo.pClearValues = clearValues; for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) { renderPassBeginInfo.framebuffer = frameBuffers[i]; VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); const VkDeviceSize offsets[1] = { 0 }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &scene.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], scene.indices.buffer, 0, VK_INDEX_TYPE_UINT32); for (auto node : scene.nodes) { renderNode(node, drawCmdBuffers[i]); } drawUI(drawCmdBuffers[i]); vkCmdEndRenderPass(drawCmdBuffers[i]); VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); } }
void Object_3DS::draw() { #ifdef HAS_LIB3DS if(!file) return ; glPushMatrix(); glMatrixMode(GL_MODELVIEW); glMultMatrix(pose); for (Lib3dsNode* p=file->nodes; p!=0; p=p->next) renderNode(p); glPopMatrix(); #endif }
void CImpostorSceneNode::doRenderQueue() { u32 currentTime = Timer->getRealTime(), endTime = currentTime + QueueMaxMS, startTime = currentTime; RenderQueue.sort(); s32 j= s32(RenderQueue.size()) - 1; s32 queueEnd = core::max_<s32>(-1, j - QueueMaxItemsPerPass); for (; j > queueEnd && currentTime <= endTime; --j) { renderNode(*(RenderQueue[j].Node)); RenderQueue[j].Node->IsQueued = false; currentTime = Timer->getRealTime(); } RenderQueue.set_used(j+1); }
void QuadTree::renderNode( TreeNode* node, Frustum* frustum, IDirect3DDevice9* device ) { //// Build AABB for node //D3DXVECTOR3 boxMin( // node->mcenterX - node->mwidth, // 0, // node->mcenterZ - node->mwidth // ); //D3DXVECTOR3 boxMax( // node->mcenterX + node->mwidth, // 0, // node->mcenterZ + node->mwidth // ); //AABB box(boxMin, boxMax); //// Determine whether current node was visible, if not visible, return. //bool isVisible = frustum->isVisable(box); D3DXVECTOR3 center(node->mcenterX, 0, node->mcenterZ); float radius = node->mwidth; bool isVisible = frustum->isVisable(center, radius); if (!isVisible) { return; } // if has child node, render child nodes, can we use node->node[0] != NULL? if (node->hasChild) { // Render child nodes for (int i = 0; i < 4; ++i) { renderNode(node->nodes[i], frustum, device); } } else // render current node { node->mmesh->DrawSubset(0); mdrawCount += node->mtriangleCount; device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); } }
bool Mipmapping::split(const Quadnode& node, std::uint8_t depth) { if (!isVisible(node, depth)) { dividNode(node, depth); return false; } if (isDivide(node, depth)) { dividNode(node, depth); return true; } disableNode(node, depth); renderNode(node, depth); return false; }
void renderNode(vkglTF::Node *node, VkCommandBuffer commandBuffer) { if (node->mesh) { for (vkglTF::Primitive * primitive : node->mesh->primitives) { const std::vector<VkDescriptorSet> descriptorsets = { descriptorSet, node->mesh->uniformBuffer.descriptorSet }; vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, static_cast<uint32_t>(descriptorsets.size()), descriptorsets.data(), 0, NULL); struct PushBlock { glm::vec4 baseColorFactor; } pushBlock; pushBlock.baseColorFactor = primitive->material.baseColorFactor; vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushBlock), &pushBlock); /* [POI] Setup the conditional rendering */ VkConditionalRenderingBeginInfoEXT conditionalRenderingBeginInfo{}; conditionalRenderingBeginInfo.sType = VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT; conditionalRenderingBeginInfo.buffer = conditionalBuffer.buffer; conditionalRenderingBeginInfo.offset = sizeof(int32_t) * node->index; /* [POI] Begin conditionally rendered section If the value from the conditional rendering buffer at the given offset is != 0, the draw commands will be executed */ vkCmdBeginConditionalRenderingEXT(commandBuffer, &conditionalRenderingBeginInfo); vkCmdDrawIndexed(commandBuffer, primitive->indexCount, 1, primitive->firstIndex, 0, 0); vkCmdEndConditionalRenderingEXT(commandBuffer); } }; for (auto child : node->children) { renderNode(child, commandBuffer); } }
void TimingProfiler::displayTimeProfiles() { const float FONT_SIZE = 22.f; Vector2 startLocation = Vector2( 0.f, (float)getTheRenderer().getCurrentResolution().y - ( FONT_SIZE ) ); Vector2 startLocationCurrent( 200.f, startLocation.y ); Vector2 startLocationAverage( 400.f, startLocation.y ); getTheTextRenderer().applyFontHeight( FONT_SIZE ); getTheTextRenderer().addTextToBeRendered( "Name", startLocation, RGBA_WHITE ); getTheTextRenderer().addTextToBeRendered( "Current", startLocationCurrent, RGBA_WHITE ); getTheTextRenderer().addTextToBeRendered( "Average", startLocationAverage, RGBA_WHITE ); Vector2 currentOffset( 0.f, -FONT_SIZE * 1.1f ); for( auto iter = m_TimingProfiles.begin(); iter != m_TimingProfiles.end(); ++iter ) { renderNode( *iter, FONT_SIZE, startLocation, startLocationCurrent, startLocationAverage, currentOffset ); } getTheTextRenderer().renderFrame( getTheRenderer().getCurrentResolution() ); }
void renderNode(Shader *shader, aiScene const * scene, aiNode *node, bool doShadows) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); aiMatrix4x4 m = node->mTransformation; m = m.Transpose(); glMultMatrixf((float *)&m); if (shader == phongShader) { // store active texture to restore afterwards GLint activeTxtUnit; glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTxtUnit); glMatrixMode(GL_TEXTURE); glActiveTexture(GL_TEXTURE6); glPushMatrix(); glMultMatrixf((float *)&m); glActiveTexture(activeTxtUnit); } for (int i = 0; i < node->mNumMeshes; i++) { int meshIndex = node->mMeshes[i]; aiMesh *mesh = scene->mMeshes[meshIndex]; if (mesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE) continue; if (shader == phongShader) { setMaterial(scene, mesh); } if (shader != simpleShader) { setTextures(shader, scene, mesh); } setMeshData(mesh, shader); // Draw the mesh std::map<aiMesh *, std::vector<unsigned>*>::iterator itr = indexBuffers.find(mesh); if (itr != indexBuffers.end()) { std::vector<unsigned> indexBuffer = *itr->second; // Found an index buffer! Draw it glDrawElements(GL_TRIANGLES, 3*mesh->mNumFaces, GL_UNSIGNED_INT, &indexBuffer[0]); } } for (int i = 0; i < node->mNumChildren; i++) { aiNode *childNode = node->mChildren[i]; renderNode(shader, scene, childNode, doShadows); } if (shader == phongShader) { // store active texture to restore afterwards GLint activeTxtUnit; glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTxtUnit); glMatrixMode(GL_TEXTURE); glActiveTexture(GL_TEXTURE6); glPopMatrix(); glActiveTexture(activeTxtUnit); } glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
// this code is rewritten from player.c example that came with lib3ds // what it does is render a node from our model void Model::renderNode(Lib3dsNode *node) { ASSERT(file); //this is for debugging { Lib3dsNode *tmp; for(tmp = node->childs;tmp != 0;tmp = tmp->next) renderNode(tmp); //render all child nodes of this note } if(node->type == LIB3DS_OBJECT_NODE) //check wheter the node is a 3ds node { if(! node->user.d) //Wheter we have a list or not, if not we're gonna create one { Lib3dsMesh *mesh = lib3ds_file_mesh_by_name(file, node->name); //get all the meshes of the current node ASSERT(mesh); //for debugging in case we don't have a mesh if(! mesh) return; node->user.d = glGenLists(1); //alocate memory for one list ///////////////////////////////////////////////////////////// if(glGetError() != GL_NO_ERROR) { cout << "ERROR!\n"; exit(0); } ///////////////////////////////////////////////////////////// glNewList(node->user.d, GL_COMPILE); //here we create our list { unsigned p; Lib3dsVector *normals; normals = static_cast<float(*)[3]> (std::malloc (3*sizeof(Lib3dsVector)*mesh->faces)); //alocate memory for our normals { Lib3dsMatrix m; lib3ds_matrix_copy(m, mesh->matrix); //copy the matrix of the mesh in our temporary matrix lib3ds_matrix_inv(m); glMultMatrixf(&m[0][0]); //adjust our current matrix to the matrix of the mesh } lib3ds_mesh_calculate_normals(mesh, normals); //calculate the normals of the mesh int j = 0; for(p = 0;p < mesh->faces;p++) { Lib3dsFace *f = &mesh->faceL[p]; Lib3dsMaterial *mat=0; if(f->material[0]) //if the face of the mesh has material properties mat = lib3ds_file_material_by_name(file, f->material); //read material properties from file if(mat) //if we have material { static GLfloat ambient[4] = { 0.0, 0.0, 0.0, 1.0 }; glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); // Ambient color glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->diffuse); //diffuse color glMaterialfv(GL_FRONT, GL_SPECULAR, mat->specular); //specular color float shine; shine = pow(2, 10.0 * mat->shininess); if(shine > 128.0) shine = 128.0; glMaterialf(GL_FRONT, GL_SHININESS, shine); } else // if we do not have material properties, we have to set them manually { GLfloat diff[4] = { 0.75, 0.75, 0.75, 1.0 }; // color: white/grey GLfloat amb[4] = { 0.25, 0.25, 0.25, 1.0 }; //color: black/dark gray GLfloat spec[4] = { 0.0, 0.0, 0.0, 1.0 }; //color: completly black glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); glMaterialfv(GL_FRONT, GL_AMBIENT, amb); glMaterialfv(GL_FRONT, GL_AMBIENT, spec); } { if(mesh->texels) { glBindTexture(GL_TEXTURE_2D, textureIndices.at(j)); j++; } glBegin(GL_TRIANGLES); for(int i = 0;i < 3;i++) { glNormal3fv(normals[3*p+i]); //set normal vector of that point if(mesh->texels) glTexCoord2f(mesh->texelL[f->points[i]][0], mesh->texelL[f->points[i]][1]); glVertex3fv(mesh->pointL[f->points[i]].pos); //Draw the damn triangle } glEnd(); } } free(normals); //free up memory } glEndList(); // end of list } if(node->user.d) // if we have created a link list(with glNewList) { Lib3dsObjectData *tmpdat; glPushMatrix(); //save transformation values tmpdat = &node->data.object; // get the position data glMultMatrixf(&node->matrix[0][0]); //adjust matrix according to the node glTranslatef(-tmpdat->pivot[0], -tmpdat->pivot[1], -tmpdat->pivot[2]); //move to the right place; glCallList(node->user.d); //render node glPopMatrix(); //return transformation original values } } }
void Object_3DS::renderNode(Lib3dsNode *node) { #ifdef HAS_LIB3DS for (Lib3dsNode* p=node->childs; p!=0; p=p->next) renderNode(p); if (node->type == LIB3DS_OBJECT_NODE) { if (strcmp(node->name,"$$$DUMMY")==0) return; if (!node->user.d) { Lib3dsMesh *mesh=lib3ds_file_mesh_by_name(file, node->name); if (!mesh) return; MSG_INFO("Rendering node %s",node->name); MSG_INFO("Face number: %d",mesh->faces); // return ; node->user.d = glGenLists(1); glNewList(node->user.d, GL_COMPILE); Lib3dsVector *normalL = new Lib3dsVector[3*mesh->faces]; Lib3dsMatrix M; lib3ds_matrix_copy(M, mesh->matrix); lib3ds_matrix_inv(M); glMultMatrixf(&M[0][0]); lib3ds_mesh_calculate_normals(mesh, normalL); for (unsigned int p=0; p<mesh->faces; ++p) { Lib3dsFace *f=&mesh->faceL[p]; Lib3dsMaterial *mat=0; if (f->material[0]) mat=lib3ds_file_material_by_name(file, f->material); if (mat) { static GLfloat a[4]={0,0,0,1}; float s; glMaterialfv(GL_FRONT, GL_AMBIENT, a); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat->specular); s = pow(2, 10.0*mat->shininess); if (s>128.0) s=128.0; glMaterialf(GL_FRONT, GL_SHININESS, s); } else { Lib3dsRgba a={0.2, 0.2, 0.2, 1.0}; Lib3dsRgba d={0.8, 0.8, 0.8, 1.0}; Lib3dsRgba s={0.0, 0.0, 0.0, 1.0}; glMaterialfv(GL_FRONT, GL_AMBIENT, a); glMaterialfv(GL_FRONT, GL_DIFFUSE, d); glMaterialfv(GL_FRONT, GL_SPECULAR, s); } glBegin(GL_TRIANGLES); glNormal3fv(f->normal); for (int i=0; i<3; ++i) { glNormal3fv(normalL[3*p+i]); glVertex3fv(mesh->pointL[f->points[i]].pos); } glEnd(); } delete[] normalL; glEndList(); } if (node->user.d) { glPushMatrix(); Lib3dsObjectData* d = &node->data.object; glMultMatrixf(&node->matrix[0][0]); glTranslatef(-d->pivot[0], -d->pivot[1], -d->pivot[2]); glCallList(node->user.d); glPopMatrix(); } } #endif }
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 BSPLoader::render() { renderNode(0); }
// Render the entire tree void QuadTree::render( Frustum* frustum, IDirect3DDevice9* device ) { mdrawCount = 0; device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); renderNode(mRoot, frustum, device); }
void generateCubeMap() { glViewport(0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE); glUseProgram(phongShader->programID()); GLint drawShadows = glGetUniformLocation(phongShader->programID(), "drawShadows"); glUniform1i(drawShadows, 0); glGenTextures(1, &cubeMapTextureID); glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTextureID); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); for (uint face = 0; face < 6; face++) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set up the projection and model-view matrices GLfloat aspectRatio = 1.0f; GLfloat nearClip = 0.1f; GLfloat farClip = 500.0f; GLfloat fieldOfView = 90.0f; // Degrees glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fieldOfView, aspectRatio, nearClip, farClip); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); switch (face) { case 0: /// positive x gluLookAt(0.0f, 2.0f, 0.0f, 1.0f, 2.0f, 0.0f, 0.0f, 1.0f, 0.0f); break; case 1: // negative x gluLookAt(0.0f, 2.0f, 0.0f, -1.0f, 2.0f, 0.0f, 0.0f, 1.0f, 0.0f); break; case 2: // positive y gluLookAt(0.0f, 2.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, -1.0f); break; case 3: // negative y gluLookAt(0.0f, 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); break; case 4: // positive z gluLookAt(0.0f, 2.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 1.0f, 0.0f); break; case 5: // negative z gluLookAt(0.0f, 2.0f, 0.0f, 0.0f, 2.0f, -1.0f, 0.0f, 1.0f, 0.0f); break; default: break; } // TODO: WHY SO DARK CUBEMAP glPushMatrix(); // set the light in the scene correctly transNode(cathedralScene, cathedralScene->mRootNode); // TODO: STILL NEED TO FIGURE OUT WHY I DO THIS GLfloat light0_position[] = { 0, 30, 0, 0 }; glLightfv( GL_LIGHT0, GL_POSITION, light0_position ); GLfloat light1_position[] = { 0, 11, 0, 0.0 }; glLightfv( GL_LIGHT1, GL_POSITION, light1_position ); glPopMatrix(); renderNode(phongShader, cathedralScene, cathedralScene->mRootNode, false); // Copy the back buffer into the current face of the cube map glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, CUBE_MAP_SIZE, CUBE_MAP_SIZE, 0, GL_RGBA, GL_FLOAT, NULL); glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0, 0, 0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE); } glUniform1i(drawShadows, 1); glViewport(0, 0, window.GetWidth(), window.GetHeight()); }