static void Init(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); InitMaterials(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef( 0.0, 0.0, -6.0 ); #ifdef GL_EXT_vertex_array if (use_vertex_arrays) { glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts ); glNormalPointerEXT( GL_FLOAT, 0, numverts, norms ); glEnable( GL_VERTEX_ARRAY_EXT ); glEnable( GL_NORMAL_ARRAY_EXT ); } #endif }
//----------------------------------------------------------------------------- // Purpose: // Input : updateType - //----------------------------------------------------------------------------- void C_PropCombineBall::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged( updateType ); if ( updateType == DATA_UPDATE_CREATED ) { m_vecLastOrigin = GetAbsOrigin(); InitMaterials(); } }
bool Mesh::InitMesh(const aiScene* pScene, const std::string& sFilepath) { assert(pScene->mNumMeshes | !"Only one mesh per scene is allowed."); m_textures.resize(pScene->mNumMaterials); const aiMesh* Mesh = pScene->mMeshes[0]; materialIndex = Mesh->mMaterialIndex; const aiVector3D zero3D(0.0f, 0.0f, 0.0f); for(unsigned int i = 0; i < Mesh->mNumVertices; ++i) { //std::cout << Mesh->mVertices[i].x << " | " << Mesh->mVertices[i].y << " | " << Mesh->mVertices[i].z << std::endl; const aiVector3D* pPos = &(Mesh->mVertices[i]); const aiVector3D* pNormal = &(Mesh->mNormals[i]); const aiVector3D* pTexCoord = Mesh->HasTextureCoords(0) ? &(Mesh->mTextureCoords[0][i]) : &zero3D; vVertices.push_back(glm::vec3(pPos->x,pPos->y,pPos->z)); vTexCoords.push_back(glm::vec2(pTexCoord->x, pTexCoord->y)); vNormals.push_back(glm::vec3(pNormal->x, pNormal->y, pNormal->z)); /*Vertex v(glm::vec3(pPos->x, pPos->y, pPos->z), glm::vec2(pTexCoord->x, pTexCoord->y), glm::vec3(pNormal->x, pNormal->y, pNormal->z)); vVertices.push_back(v);*/ } for(unsigned int i = 0; i < Mesh->mNumFaces; ++i) { const aiFace& face = Mesh->mFaces[i]; assert(face.mNumIndices == 3); vIndicies.push_back(face.mIndices[0]); vIndicies.push_back(face.mIndices[1]); vIndicies.push_back(face.mIndices[2]); } numIndicies = vIndicies.size(); //for(int j = 0; j < Mesh->mNumFaces * 3; j++) //{ //std::cout << faceArray[j]; //std::cout << &vVertices[j] << " | " << vVertices[j].x << " | "<< vVertices[j].y <<" | " << vVertices[j].z << j<< std::endl; //std::cout << &vVertices[j] << " | " << vVertices[j].y << " | "<< j; //std::cout << &vVertices[j] << " | " << vVertices[j].z << " | "<< j << std::endl; //} return InitMaterials(pScene, sFilepath); }
void SceneBase::Init(string vertexShader, string fragmentShader) { // Debug m_bShowDebug = false; // Simulation Speed m_speed = 1.0f; // Dark Blue Background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); // Face Culling glEnable(GL_CULL_FACE); m_bCull = true; // Filled/Wireframe Mode glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_bWireframe = false; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glGenVertexArrays(1, &m_vertexArrayID); glBindVertexArray(m_vertexArrayID); Math::InitRNG(); InitShadersAndLights(vertexShader, fragmentShader); InitFog(); /* * Resource Initialization */ // Colors InitColors(); // Materials InitMaterials(); // Textures InitTextures(); // Meshes InitMeshes(); // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 1000 units Mtx44 perspective; perspective.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 12000.0f); //perspective.SetToOrtho(-80, 80, -60, 60, -1000, 1000); projectionStack.LoadMatrix(perspective); bLightEnabled = true; }
//----------------------------------------------------------------------------- // Purpose: // Input : flags - // Output : int //----------------------------------------------------------------------------- int C_PropCombineBall::DrawModel( int flags ) { if ( !m_bEmit ) return 0; // Make sure our materials are cached if ( !InitMaterials() ) { //NOTENOTE: This means that a material was not found for the combine ball, so it may not render! AssertOnce( 0 ); return 0; } // Draw the flickering overlay DrawFlicker(); // Draw the motion blur from movement if ( m_bHeld || m_bLaunched ) { DrawMotionBlur(); } // Draw the model if we're being held if ( m_bHeld ) { QAngle angles; VectorAngles( -CurrentViewForward(), angles ); // Always orient towards the camera! SetAbsAngles( angles ); BaseClass::DrawModel( flags ); } else { float color[3]; color[0] = color[1] = color[2] = 1.0f; float sinOffs = 1.0f * sin( gpGlobals->curtime * 25 ); float roll = SpawnTime(); // Draw the main ball body CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( m_pBodyMaterial, (C_BaseEntity*) this ); DrawHaloOriented( GetAbsOrigin(), m_flRadius + sinOffs, color, roll ); } m_vecLastOrigin = GetAbsOrigin(); return 1; }
bool Mesh::InitFromScene(const aiScene* pScene, const std::string& filePath) { m_entries.resize(pScene->mNumMeshes); m_textures.resize(pScene->mNumMaterials); for(unsigned int i = 0; i < m_entries.size(); ++i) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, filePath); }
//--------------------------------------- bool Mesh::InitScene( const aiScene* scene, const char* filename ) { mEntries.resize( scene->mNumMeshes ); mTextures.resize( scene->mNumMaterials ); for ( unsigned i = 0; i < mEntries.size(); ++i ) { const aiMesh* mesh = scene->mMeshes[i]; InitMesh( i, mesh ); } return InitMaterials( scene, filename ); }
bool Mesh::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); for (unsigned int i = 0; i < m_Entries.size(); i++){ const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, Filename); }
bool COpenAssetImporterMesh::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); // Initialize the meshes in the scene one by one for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, Filename); }
bool Mesh::InitFromScene ( const aiScene* pScene, const std::string& filename ) { m_entries.resize ( pScene->mNumMeshes ); m_textures.resize ( pScene->mNumMaterials ); // Инициализируем меши один за другим for ( unsigned int i = 0; i < m_entries.size ( ); i++ ) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh ( i, paiMesh ); } return InitMaterials ( pScene, filename ); }
void Model::InitMesh(const aiScene* pScene, unsigned int Index, aiColor3D color) { m_Entries[Index].MaterialIndex = pScene->mMeshes[Index]->mMaterialIndex; std::vector<Vertex> Vertices; std::vector<unsigned int> Indices; const aiVector3D Zero3D(0.0f, 0.0f, 0.0f); // initialize all the vertices in the mesh for (unsigned int i = 0 ; i < pScene->mMeshes[Index]->mNumVertices ; i++) { const aiVector3D* pPos = &(pScene->mMeshes[Index]->mVertices[i]); Vertex v; v.position[0] = pPos->x; v.position[1] = pPos->y; v.position[2] = pPos->z; // check if there is a texture for this mesh if (pScene->mMeshes[Index]->HasTextureCoords(0)) { aiVector3D textureCoord = pScene->mMeshes[Index]->mTextureCoords[0][i]; v.uv[0] = textureCoord.x; v.uv[1] = textureCoord.y; } if (pScene->mMeshes[Index]->HasNormals()) { const aiVector3D* normal = &(pScene->mMeshes[Index]->mNormals[i]); v.normal[0] = normal->x; v.normal[1] = normal->y; v.normal[2] = normal->z; } Vertices.push_back(v); } // store the indices of the faces in the mesh for (unsigned int i = 0 ; i < pScene->mMeshes[Index]->mNumFaces; i++) { const aiFace& Face = pScene->mMeshes[Index]->mFaces[i]; assert(Face.mNumIndices == 3); Indices.push_back(Face.mIndices[0]); Indices.push_back(Face.mIndices[1]); Indices.push_back(Face.mIndices[2]); } // get texture InitMaterials(pScene, Index); // bind buffers m_Entries[Index].Init(Vertices, Indices); }
static void Init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); InitMaterials(); InitTexture(); InitMesh(); glMatrixMode(GL_MODELVIEW); glTranslatef(0.0, 0.4, -1.8); glScalef(2.0, 2.0, 2.0); glRotatef(-35.0, 1.0, 0.0, 0.0); glRotatef(35.0, 0.0, 0.0, 1.0); }
void Ship::Init() { m_invulnerable = false; m_sensors.reset(new Sensors(this)); m_navLights.reset(new NavLights(GetModel())); m_navLights->SetEnabled(true); SetMassDistributionFromModel(); UpdateEquipStats(); m_stats.hull_mass_left = float(m_type->hullMass); m_stats.shield_mass_left = 0; PropertyMap &p = Properties(); p.Set("hullMassLeft", m_stats.hull_mass_left); p.Set("hullPercent", 100.0f * (m_stats.hull_mass_left / float(m_type->hullMass))); p.Set("shieldMassLeft", m_stats.shield_mass_left); p.Set("fuelMassLeft", m_stats.fuel_tank_mass_left); p.Set("shipName", m_shipName); m_hyperspace.now = false; // TODO: move this on next savegame change, maybe m_hyperspaceCloud = 0; m_landingGearAnimation = GetModel()->FindAnimation("gear_down"); InitGun("tag_gunmount_0", 0); InitGun("tag_gunmount_1", 1); // If we've got the tag_landing set then use it for an offset otherwise grab the AABB const SceneGraph::MatrixTransform *mt = GetModel()->FindTagByName("tag_landing"); if( mt ) { m_landingMinOffset = mt->GetTransform().GetTranslate().y; } else { m_landingMinOffset = GetAabb().min.y; } InitMaterials(); }
GRAPHICS::GRAPHICS(HWND in_hwnd) : hwnd(in_hwnd) { try { d3d = Direct3DCreate9(D3D_SDK_VERSION); if (!d3d) throw 0; try { CreateDirect3DDevice(); try { InitVBCube(); } catch(...) { d3ddev->Release(); throw; } } catch(...) { d3d->Release(); throw; } } catch(...) { throw; } InitLights(); InitMaterials(); strWorld.rotationY = 0.0f; strWorld.rotationZ = 0.0f; strView.camera_pos = D3DXVECTOR3(6.0f, 0.0f, 0.0f); strView.look_at_point = D3DXVECTOR3(0.0f, 0.0f, 0.0f); strView.up_direction = D3DXVECTOR3(0.0f, 0.0f, 1.0f); strProjection.angle = 45; strProjection.plane_near = 1.0f; strProjection.plane_far = 100.0f; UpdateMatrixWorld(); UpdateMatrixView(); UpdateMatrixProjection(); }
void lterrain::InitMaterials(const materialscript* M, const materialscript*, truth CUP) { InitMaterials(M->Instantiate(), CUP); }
void PathOCLRenderThread::InitRender() { Scene *scene = renderEngine->renderConfig->scene; cl::Context &oclContext = intersectionDevice->GetOpenCLContext(); cl::Device &oclDevice = intersectionDevice->GetOpenCLDevice(); const OpenCLDeviceDescription *deviceDesc = intersectionDevice->GetDeviceDesc(); double tStart, tEnd; //-------------------------------------------------------------------------- // FrameBuffer definition //-------------------------------------------------------------------------- InitFrameBuffer(); //-------------------------------------------------------------------------- // Camera definition //-------------------------------------------------------------------------- InitCamera(); //-------------------------------------------------------------------------- // Scene geometry //-------------------------------------------------------------------------- InitGeometry(); //-------------------------------------------------------------------------- // Translate material definitions //-------------------------------------------------------------------------- InitMaterials(); //-------------------------------------------------------------------------- // Translate area lights //-------------------------------------------------------------------------- InitAreaLights(); //-------------------------------------------------------------------------- // Check if there is an infinite light source //-------------------------------------------------------------------------- InitInfiniteLight(); //-------------------------------------------------------------------------- // Check if there is an sun light source //-------------------------------------------------------------------------- InitSunLight(); //-------------------------------------------------------------------------- // Check if there is an sky light source //-------------------------------------------------------------------------- InitSkyLight(); const unsigned int areaLightCount = renderEngine->compiledScene->areaLights.size(); if (!skyLightBuff && !sunLightBuff && !infiniteLightBuff && (areaLightCount == 0)) throw runtime_error("There are no light sources supported by PathOCL in the scene"); //-------------------------------------------------------------------------- // Translate mesh texture maps //-------------------------------------------------------------------------- InitTextureMaps(); //-------------------------------------------------------------------------- // Allocate Ray/RayHit buffers //-------------------------------------------------------------------------- const unsigned int taskCount = renderEngine->taskCount; tStart = WallClockTime(); LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Ray buffer size: " << (sizeof(Ray) * taskCount / 1024) << "Kbytes"); raysBuff = new cl::Buffer(oclContext, CL_MEM_READ_WRITE, sizeof(Ray) * taskCount); deviceDesc->AllocMemory(raysBuff->getInfo<CL_MEM_SIZE>()); LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] RayHit buffer size: " << (sizeof(RayHit) * taskCount / 1024) << "Kbytes"); hitsBuff = new cl::Buffer(oclContext, CL_MEM_READ_WRITE, sizeof(RayHit) * taskCount); deviceDesc->AllocMemory(hitsBuff->getInfo<CL_MEM_SIZE>()); tEnd = WallClockTime(); LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] OpenCL buffer creation time: " << int((tEnd - tStart) * 1000.0) << "ms"); //-------------------------------------------------------------------------- // Allocate GPU task buffers //-------------------------------------------------------------------------- // TODO: clenup all this mess const size_t gpuTaksSizePart1 = // Seed size sizeof(PathOCL::Seed); const size_t uDataEyePathVertexSize = // IDX_SCREEN_X, IDX_SCREEN_Y sizeof(float) * 2 + // IDX_DOF_X, IDX_DOF_Y ((scene->camera->lensRadius > 0.f) ? (sizeof(float) * 2) : 0); const size_t uDataPerPathVertexSize = // IDX_TEX_ALPHA, ((texMapAlphaBuff) ? sizeof(float) : 0) + // IDX_BSDF_X, IDX_BSDF_Y, IDX_BSDF_Z sizeof(float) * 3 + // IDX_DIRECTLIGHT_X, IDX_DIRECTLIGHT_Y, IDX_DIRECTLIGHT_Z (((areaLightCount > 0) || sunLightBuff) ? (sizeof(float) * 3) : 0) + // IDX_RR sizeof(float); const size_t uDataSize = (renderEngine->sampler->type == PathOCL::INLINED_RANDOM) ? // Only IDX_SCREEN_X, IDX_SCREEN_Y (sizeof(float) * 2) : ((renderEngine->sampler->type == PathOCL::METROPOLIS) ? (sizeof(float) * 2 + sizeof(unsigned int) * 5 + sizeof(Spectrum) + 2 * (uDataEyePathVertexSize + uDataPerPathVertexSize * renderEngine->maxPathDepth)) : (uDataEyePathVertexSize + uDataPerPathVertexSize * renderEngine->maxPathDepth)); size_t sampleSize = // uint pixelIndex; ((renderEngine->sampler->type == PathOCL::METROPOLIS) ? 0 : sizeof(unsigned int)) + uDataSize + // Spectrum radiance; sizeof(Spectrum); stratifiedDataSize = 0; if (renderEngine->sampler->type == PathOCL::STRATIFIED) { PathOCL::StratifiedSampler *s = (PathOCL::StratifiedSampler *)renderEngine->sampler; stratifiedDataSize = // stratifiedScreen2D sizeof(float) * s->xSamples * s->ySamples * 2 + // stratifiedDof2D ((scene->camera->lensRadius > 0.f) ? (sizeof(float) * s->xSamples * s->ySamples * 2) : 0) + // stratifiedAlpha1D ((texMapAlphaBuff) ? (sizeof(float) * s->xSamples) : 0) + // stratifiedBSDF2D sizeof(float) * s->xSamples * s->ySamples * 2 + // stratifiedBSDF1D sizeof(float) * s->xSamples + // stratifiedLight2D // stratifiedLight1D (((areaLightCount > 0) || sunLightBuff) ? (sizeof(float) * s->xSamples * s->ySamples * 2 + sizeof(float) * s->xSamples) : 0); sampleSize += stratifiedDataSize; } const size_t gpuTaksSizePart2 = sampleSize; const size_t gpuTaksSizePart3 = // PathState size ((((areaLightCount > 0) || sunLightBuff) ? sizeof(PathOCL::PathStateDL) : sizeof(PathOCL::PathState)) + //unsigned int diffuseVertexCount; ((renderEngine->maxDiffusePathVertexCount < renderEngine->maxPathDepth) ? sizeof(unsigned int) : 0)); const size_t gpuTaksSize = gpuTaksSizePart1 + gpuTaksSizePart2 + gpuTaksSizePart3; LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Size of a GPUTask: " << gpuTaksSize << "bytes (" << gpuTaksSizePart1 << " + " << gpuTaksSizePart2 << " + " << gpuTaksSizePart3 << ")"); LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Tasks buffer size: " << (gpuTaksSize * taskCount / 1024) << "Kbytes"); // Check if the task buffer is too big if (oclDevice.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>() < gpuTaksSize * taskCount) { stringstream ss; ss << "The GPUTask buffer is too big for this device (i.e. CL_DEVICE_MAX_MEM_ALLOC_SIZE=" << oclDevice.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>() << "): try to reduce opencl.task.count and/or path.maxdepth and/or to change Sampler"; throw std::runtime_error(ss.str()); } tasksBuff = new cl::Buffer(oclContext, CL_MEM_READ_WRITE, gpuTaksSize * taskCount); deviceDesc->AllocMemory(tasksBuff->getInfo<CL_MEM_SIZE>()); //-------------------------------------------------------------------------- // Allocate GPU task statistic buffers //-------------------------------------------------------------------------- LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Task Stats buffer size: " << (sizeof(PathOCL::GPUTaskStats) * taskCount / 1024) << "Kbytes"); taskStatsBuff = new cl::Buffer(oclContext, CL_MEM_READ_WRITE, sizeof(PathOCL::GPUTaskStats) * taskCount); deviceDesc->AllocMemory(taskStatsBuff->getInfo<CL_MEM_SIZE>()); //-------------------------------------------------------------------------- // Compile kernels //-------------------------------------------------------------------------- InitKernels(); //-------------------------------------------------------------------------- // Initialize //-------------------------------------------------------------------------- // Set kernel arguments SetKernelArgs(); cl::CommandQueue &oclQueue = intersectionDevice->GetOpenCLQueue(); // Clear the frame buffer oclQueue.enqueueNDRangeKernel(*initFBKernel, cl::NullRange, cl::NDRange(RoundUp<unsigned int>(frameBufferPixelCount, initFBWorkGroupSize)), cl::NDRange(initFBWorkGroupSize)); // Initialize the tasks buffer oclQueue.enqueueNDRangeKernel(*initKernel, cl::NullRange, cl::NDRange(taskCount), cl::NDRange(initWorkGroupSize)); oclQueue.finish(); // Reset statistics in order to be more accurate intersectionDevice->ResetPerformaceStats(); }
void PathOCLRenderThread::EndEdit(const EditActionList &editActions) { //-------------------------------------------------------------------------- // Update OpenCL buffers //-------------------------------------------------------------------------- if (editActions.Has(FILM_EDIT)) { // Resize the Framebuffer InitFrameBuffer(); } if (editActions.Has(CAMERA_EDIT)) { // Update Camera InitCamera(); } if (editActions.Has(GEOMETRY_EDIT)) { // Update Scene Geometry InitGeometry(); } if (editActions.Has(MATERIALS_EDIT) || editActions.Has(MATERIAL_TYPES_EDIT)) { // Update Scene Materials InitMaterials(); } if (editActions.Has(AREALIGHTS_EDIT)) { // Update Scene Area Lights InitAreaLights(); } if (editActions.Has(INFINITELIGHT_EDIT)) { // Update Scene Infinite Light InitInfiniteLight(); } if (editActions.Has(SUNLIGHT_EDIT)) { // Update Scene Sun Light InitSunLight(); } if (editActions.Has(SKYLIGHT_EDIT)) { // Update Scene Sun Light InitSkyLight(); } //-------------------------------------------------------------------------- // Recompile Kernels if required //-------------------------------------------------------------------------- if (editActions.Has(FILM_EDIT) || editActions.Has(MATERIAL_TYPES_EDIT)) InitKernels(); if (editActions.Size() > 0) SetKernelArgs(); //-------------------------------------------------------------------------- // Execute initialization kernels //-------------------------------------------------------------------------- if (editActions.Size() > 0) { cl::CommandQueue &oclQueue = intersectionDevice->GetOpenCLQueue(); // Clear the frame buffer oclQueue.enqueueNDRangeKernel(*initFBKernel, cl::NullRange, cl::NDRange(RoundUp<unsigned int>(frameBufferPixelCount, initFBWorkGroupSize)), cl::NDRange(initFBWorkGroupSize)); // Initialize the tasks buffer oclQueue.enqueueNDRangeKernel(*initKernel, cl::NullRange, cl::NDRange(renderEngine->taskCount), cl::NDRange(initWorkGroupSize)); } // Reset statistics in order to be more accurate intersectionDevice->ResetPerformaceStats(); StartRenderThread(); }
static void Init(int argc, char *argv[]) { GLfloat fogColor[4] = {0.5,1.0,0.5,1.0}; xrot = 0; yrot = 0; dist = -6; plane[0] = 1.0; plane[1] = 0.0; plane[2] = -1.0; plane[3] = 0.0; glClearColor(0.0, 0.0, 1.0, 0.0); glEnable( GL_DEPTH_TEST ); glEnable( GL_VERTEX_ARRAY_EXT ); glEnable( GL_NORMAL_ARRAY_EXT ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClipPlane(GL_CLIP_PLANE0, plane); InitMaterials(); set_matrix(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); /* Green fog is easy to see */ glFogi(GL_FOG_MODE,GL_EXP2); glFogfv(GL_FOG_COLOR,fogColor); glFogf(GL_FOG_DENSITY,0.15); glHint(GL_FOG_HINT,GL_DONT_CARE); { static int firsttime = 1; if (firsttime) { firsttime = 0; compactify_arrays(); expand_arrays(); make_tri_indices(); if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { printf("Error: couldn't load texture image\n"); exit(1); } } } ModeMenu(SHADE_SMOOTH| LIT| POINT_FILTER| NO_USER_CLIP| NO_MATERIALS| NO_FOG| NO_STIPPLE| IMMEDIATE| STRIPS| UNLOCKED| GLVERTEX); if (PrintInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); } }
bool BasicMesh::InitFromScene(const aiScene* pScene, const string& Filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); vector<Vector3f> Positions; vector<Vector3f> Normals; vector<Vector2f> TexCoords; vector<unsigned int> Indices; unsigned int NumVertices = 0; unsigned int NumIndices = 0; // Count the number of vertices and indices for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { m_Entries[i].MaterialIndex = pScene->mMeshes[i]->mMaterialIndex; m_Entries[i].NumIndices = pScene->mMeshes[i]->mNumFaces * 3; m_Entries[i].BaseVertex = NumVertices; m_Entries[i].BaseIndex = NumIndices; NumVertices += pScene->mMeshes[i]->mNumVertices; NumIndices += m_Entries[i].NumIndices; } // Reserve space in the vectors for the vertex attributes and indices Positions.reserve(NumVertices); Normals.reserve(NumVertices); TexCoords.reserve(NumVertices); Indices.reserve(NumIndices); // Initialize the meshes in the scene one by one for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(paiMesh, Positions, Normals, TexCoords, Indices); } if (!InitMaterials(pScene, Filename)) { return false; } // Generate and populate the buffers with vertex attributes and the indices glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0], GL_STATIC_DRAW); glEnableVertexAttribArray(POSITION_LOCATION); glVertexAttribPointer(POSITION_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0], GL_STATIC_DRAW); glEnableVertexAttribArray(TEX_COORD_LOCATION); glVertexAttribPointer(TEX_COORD_LOCATION, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0], GL_STATIC_DRAW); glEnableVertexAttribArray(NORMAL_LOCATION); glVertexAttribPointer(NORMAL_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size(), &Indices[0], GL_STATIC_DRAW); return GLCheckError(); }
bool Animation::Mesh::InitFromScene(const aiScene* scene, const std::string& filename) { Clear(); GenBuffers(); m_meshes.resize(scene->mNumMeshes); std::vector<unsigned int> indices; std::vector<VertexInfo> vertices; m_numVertices = 0; m_numIndices = 0; Assign(m_GlobalInverseTransform, scene->mRootNode->mTransformation); m_GlobalInverseTransform = glm::inverse(m_GlobalInverseTransform); // Count the number of vertices and indices for (unsigned int i = 0; i < m_meshes.size(); i++) { m_meshes[i].materialIndex = scene->mMeshes[i]->mMaterialIndex; m_meshes[i].numIndices = scene->mMeshes[i]->mNumFaces * 3; m_meshes[i].baseVertex = m_numVertices; m_meshes[i].baseIndex = m_numIndices; m_numVertices += scene->mMeshes[i]->mNumVertices; m_numIndices += m_meshes[i].numIndices; } // Reserve space in the vectors for the vertex attributes and indices vertices.reserve(m_numVertices); indices.reserve(m_numIndices); InitNodeHierarchy(m_rootNode, scene->mRootNode); // Initialize the meshes in the scene one by one for (unsigned int i = 0; i < m_meshes.size(); i++) { const aiMesh* paiMesh = scene->mMeshes[i]; InitMesh(i, paiMesh, vertices, indices); } if (!InitMaterials(scene, filename)) return false; // Populate the buffers with vertex attributes and the indices glBindVertexArray(m_VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices[0]) * indices.size(), &indices[0], GL_STATIC_DRAW); // Load data glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(VertexInfo) * vertices.size(), &vertices[0], GL_STATIC_DRAW); glEnableVertexAttribArray(POSITION_LOCATION); glVertexAttribPointer(POSITION_LOCATION, 3, GL_FLOAT, GL_FALSE, sizeof(VertexInfo), (GLvoid*)0); glEnableVertexAttribArray(TEX_COORD_LOCATION); glVertexAttribPointer(TEX_COORD_LOCATION, 2, GL_FLOAT, GL_FALSE, sizeof(VertexInfo), (GLvoid*)offsetof(VertexInfo, texCoords)); glEnableVertexAttribArray(NORMAL_LOCATION); glVertexAttribPointer(NORMAL_LOCATION, 3, GL_FLOAT, GL_FALSE, sizeof(VertexInfo), (GLvoid*)offsetof(VertexInfo, normal)); glEnableVertexAttribArray(BONE_ID_LOCATION); glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_UNSIGNED_INT, sizeof(VertexInfo), // Cannot pass more than 4!! (GLvoid*)offsetof(VertexInfo, boneData.IDs)); glEnableVertexAttribArray(BONE_WEIGHT_LOCATION); glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexInfo), // Cannot pass more than 4!! (GLvoid*)offsetof(VertexInfo, boneData.weights)); glBindVertexArray(0); // Make sure the VAO is not changed from the outside return glGetError() == GL_NO_ERROR; }
void CompModel::SetModel(const std::shared_ptr<model::Model>& model) { m_model = model; InitMaterials(); }