void LoadShaders() { // Load shaders and create shader programs shShaders[0].LoadShader("data\\shaders\\tut09\\shader.vert", GL_VERTEX_SHADER); shShaders[1].LoadShader("data\\shaders\\tut09\\shader.frag", GL_FRAGMENT_SHADER); shShaders[2].LoadShader("data\\shaders\\common\\directionalLight.frag", GL_FRAGMENT_SHADER); shShaders[3].LoadShader("data\\shaders\\tut09\\ortho2D.vert", GL_VERTEX_SHADER); shShaders[4].LoadShader("data\\shaders\\tut09\\ortho2D.frag", GL_FRAGMENT_SHADER); shShaders[5].LoadShader("data\\shaders\\tut09\\font2D.frag", GL_FRAGMENT_SHADER); spDirectionalLight.CreateProgram(); spDirectionalLight.AddShaderToProgram(&shShaders[0]); spDirectionalLight.AddShaderToProgram(&shShaders[1]); spDirectionalLight.AddShaderToProgram(&shShaders[2]); spDirectionalLight.LinkProgram(); spOrtho2D.CreateProgram(); spOrtho2D.AddShaderToProgram(&shShaders[3]); spOrtho2D.AddShaderToProgram(&shShaders[4]); spOrtho2D.LinkProgram(); spFont2D.CreateProgram(); spFont2D.AddShaderToProgram(&shShaders[3]); spFont2D.AddShaderToProgram(&shShaders[5]); spFont2D.LinkProgram(); }
// Initialisation: This method only runs once at startup void Game::Initialise() { // Set the clear colour and depth glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); /// Create objects m_pCamera = new CCamera; m_pSkybox = new CSkybox; m_pShaderPrograms = new vector <CShaderProgram *>; m_pSphere = new CSphere; m_pGrid = new CGrid; #ifdef _WIN32 m_pFtFont = new CFreeTypeFont; RECT dimensions = m_gameWindow.GetDimensions(); m_width = dimensions.right - dimensions.left; m_height = dimensions.bottom - dimensions.top; #endif // Set the orthographic and perspective projection matrices based on the image size m_pCamera->SetOrthographicProjectionMatrix(m_width, m_height); m_pCamera->SetPerspectiveProjectionMatrix(45.0f, (float) m_width / (float) m_height, 0.5f, 5000.0f); // Load shaders vector<CShader> shShaders; vector<string> sShaderFileNames; sShaderFileNames.push_back("mainShader.vert"); sShaderFileNames.push_back("mainShader.frag"); sShaderFileNames.push_back("textShader.vert"); sShaderFileNames.push_back("textShader.frag"); sShaderFileNames.push_back("sphereShader.vert"); sShaderFileNames.push_back("sphereShader.frag"); for (int i = 0; i < (int) sShaderFileNames.size(); i++) { string sExt = sShaderFileNames[i].substr((int) sShaderFileNames[i].size()-4, 4); int iShaderType; if (sExt == "vert") iShaderType = GL_VERTEX_SHADER; else if (sExt == "frag") iShaderType = GL_FRAGMENT_SHADER; else if (sExt == "geom") iShaderType = GL_GEOMETRY_SHADER; else if (sExt == "tcnl") iShaderType = GL_TESS_CONTROL_SHADER; else iShaderType = GL_TESS_EVALUATION_SHADER; CShader shader; std::string shaderFile = resourcePath(sShaderFileNames[i], "shaders", ""); shader.LoadShader(shaderFile, iShaderType); shShaders.push_back(shader); } // Create the main shader program CShaderProgram *pMainProgram = new CShaderProgram; pMainProgram->CreateProgram(); pMainProgram->AddShaderToProgram(&shShaders[0]); pMainProgram->AddShaderToProgram(&shShaders[1]); pMainProgram->LinkProgram(); m_pShaderPrograms->push_back(pMainProgram); // Create a shader program for fonts CShaderProgram *pFontProgram = new CShaderProgram; pFontProgram->CreateProgram(); pFontProgram->AddShaderToProgram(&shShaders[2]); pFontProgram->AddShaderToProgram(&shShaders[3]); pFontProgram->LinkProgram(); m_pShaderPrograms->push_back(pFontProgram); #ifdef _WIN32 m_pFtFont->LoadSystemFont("arial.ttf", 32); m_pFtFont->SetShaderProgram(pFontProgram); #endif // Create the sphere shader program CShaderProgram *pSphereProgram = new CShaderProgram; pSphereProgram->CreateProgram(); pSphereProgram->AddShaderToProgram(&shShaders[4]); pSphereProgram->AddShaderToProgram(&shShaders[5]); pSphereProgram->LinkProgram(); m_pShaderPrograms->push_back(pSphereProgram); // Create a sphere std::string textureDir = resourcePath("", "textures", ""); m_pSphere->Create(textureDir, "dirtpile01.jpg", 35, 35); // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013 glEnable(GL_CULL_FACE); // Create the grid m_pGrid->Create(500, 500, 15); }
// Initializes OpenGL features that will be used. // lpParam - Pointer to anything you want. void InitScene(LPVOID lpParam) { //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Новый цвет фона glClearColor(0.0f, 0.5f, 1.0f, 1.0f); // Setup triangle vertices fTriangle[0] = -0.9f; fTriangle[1] = 0.7f; fTriangle[2] = 0.0f; fTriangle[3] = -0.7f; fTriangle[4] = 0.9f; fTriangle[5] = 0.0f; fTriangle[6] = -0.5f; fTriangle[7] = 0.7f; fTriangle[8] = 0.0f; // Setup triangle color fTriangleColor[0] = 1.0f; fTriangleColor[1] = 0.0f; fTriangleColor[2] = 0.0f; fTriangleColor[3] = 0.0f; fTriangleColor[4] = 1.0f; fTriangleColor[5] = 0.0f; fTriangleColor[6] = 0.0f; fTriangleColor[7] = 0.0f; fTriangleColor[8] = 1.0f; // Setup quad vertices fQuad[0] = 0.7f; fQuad[1] = 0.9f; fQuad[2] = 0.0f; fQuad[3] = 0.7f; fQuad[4] = 0.6f; fQuad[5] = 0.0f; fQuad[6] = 0.9f; fQuad[7] = 0.9f; fQuad[8] = 0.0f; fQuad[9] = 0.9f; fQuad[10] = 0.6f; fQuad[11] = 0.0f; // Setup quad color fQuadColor[0] = 1.0f; fQuadColor[1] = 0.0f; fQuadColor[2] = 0.0f; fQuadColor[3] = 0.0f; fQuadColor[4] = 1.0f; fQuadColor[8] = 0.0f; fQuadColor[6] = 0.0f; fQuadColor[7] = 0.0f; fQuadColor[5] = 1.0f; fQuadColor[9] = 1.0f; fQuadColor[10] = 1.0f; fQuadColor[11] = 0.0f; // Setup duck vertices fDuck[0] = 0.0f; fDuck[1] = 0.8f; fDuck[2] = 0.0f; fDuck[3] = -0.2f; fDuck[4] = 0.4f; fDuck[5] = 0.0f; fDuck[6] = -0.2f; fDuck[7] = -0.3f; fDuck[8] = 0.0f; fDuck[9] = -0.3f; fDuck[10] = -0.5f; fDuck[11] = 0.0f; fDuck[12] = -0.3f; fDuck[13] = -0.9f; fDuck[14] = 0.0f; fDuck[15] = -0.2f; fDuck[16] = -0.9f; fDuck[17] = 0.0f; fDuck[18] = -0.2f; fDuck[19] = -0.7f; fDuck[20] = 0.0f; fDuck[21] = -0.05f; fDuck[22] = -0.7f; fDuck[23] = 0.0f; fDuck[24] = -0.05f; fDuck[25] = -0.9f; fDuck[26] = 0.0f; fDuck[27] = 0.05f; fDuck[28] = -0.9f; fDuck[29] = 0.0f; fDuck[30] = 0.05f; fDuck[31] = -0.7f; fDuck[32] = 0.0f; fDuck[33] = 0.2f; fDuck[34] = -0.7f; fDuck[35] = 0.0f; fDuck[36] = 0.2f; fDuck[37] = -0.9f; fDuck[38] = 0.0f; fDuck[39] = 0.3f; fDuck[40] = -0.9f; fDuck[41] = 0.0f; fDuck[42] = 0.3f; fDuck[43] = -0.5f; fDuck[44] = 0.0f; fDuck[45] = 0.2f; fDuck[46] = -0.3f; fDuck[47] = 0.0f; fDuck[48] = 0.2f; fDuck[49] = 0.4f; fDuck[50] = 0.0f; fDuck[51] = 0.0f; fDuck[52] = 0.8f; fDuck[53] = 0.0f; // Setup duck color fDuckColor[0] = 1.0f; fDuckColor[1] = 0.0f; fDuckColor[2] = 0.0f; fDuckColor[3] = 1.0f; fDuckColor[4] = 1.0f; fDuckColor[5] = 0.0f; fDuckColor[6] = 1.0f; fDuckColor[7] = 0.0f; fDuckColor[8] = 1.0f; fDuckColor[9] = 1.0f; fDuckColor[10] = 0.0f; fDuckColor[11] = 0.0f; fDuckColor[12] = 1.0f; fDuckColor[13] = 1.0f; fDuckColor[14] = 0.0f; fDuckColor[15] = 1.0f; fDuckColor[16] = 0.0f; fDuckColor[17] = 1.0f; fDuckColor[18] = 1.0f; fDuckColor[19] = 0.0f; fDuckColor[20] = 0.0f; fDuckColor[21] = 1.0f; fDuckColor[22] = 1.0f; fDuckColor[23] = 0.0f; fDuckColor[24] = 1.0f; fDuckColor[25] = 0.0f; fDuckColor[26] = 1.0f; fDuckColor[27] = 1.0f; fDuckColor[28] = 0.0f; fDuckColor[29] = 0.0f; fDuckColor[30] = 1.0f; fDuckColor[31] = 1.0f; fDuckColor[32] = 0.0f; fDuckColor[33] = 0.2f; fDuckColor[34] = -0.7f; fDuckColor[35] = 0.0f; fDuckColor[36] = 0.2f; fDuckColor[37] = -0.9f; fDuckColor[38] = 0.0f; fDuckColor[39] = 0.3f; fDuckColor[40] = -0.9f; fDuckColor[41] = 0.0f; fDuckColor[42] = 0.3f; fDuckColor[43] = -0.5f; fDuckColor[44] = 0.0f; fDuckColor[45] = 0.2f; fDuckColor[46] = -0.3f; fDuckColor[47] = 0.0f; fDuckColor[48] = 0.2f; fDuckColor[49] = -0.3f; fDuckColor[50] = 0.0f; fDuckColor[51] = 1.0f; fDuckColor[52] = 0.0f; fDuckColor[53] = 0.0f; // Setup duck vertices fMore[0] = 0.0f; fMore[1] = 0.0f; fMore[2] = 0.0f; fMore[3] = 0.5f; fMore[4] = 0.0f; fMore[5] = 0.0f; fMore[6] = 0.5f; fMore[7] = 0.5f; fMore[8] = 0.0f; fMore[9] = 0.0f; fMore[10] = 0.0f; fMore[11] = 0.0f; fMore[12] = 0.0f; fMore[13] = 0.5f; fMore[14] = 0.0f; fMore[15] = -0.5f; fMore[16] = 0.5f; fMore[17] = 0.0f; fMore[18] = 0.0f; fMore[19] = 0.0f; fMore[20] = 0.0f; fMore[21] = -0.5f; fMore[22] = 0.0f; fMore[23] = 0.0f; fMore[24] = -0.5f; fMore[25] = -0.5f; fMore[26] = 0.0f; fMore[27] = 0.0f; fMore[28] = 0.0f; fMore[29] = 0.0f; fMore[30] = 0.0f; fMore[31] = -0.5f; fMore[32] = 0.0f; fMore[33] = 0.5f; fMore[34] = -0.5f; fMore[35] = 0.0f; for (int i = 0; i < 36; i++) { fMore[i] = fMore[i] * 0.4 - 0.6f; } // Setup duck color fMoreColor[0] = 1.0f; fMoreColor[1] = 1.0f; fMoreColor[2] = 1.0f; fMoreColor[3] = 1.0f; fMoreColor[4] = 1.0f; fMoreColor[5] = 1.0f; fMoreColor[6] = 1.0f; fMoreColor[7] = 1.0f; fMoreColor[8] = 1.0f; fMoreColor[9] = 1.0f; fMoreColor[10] = 0.0f; fMoreColor[11] = 0.0f; fMoreColor[12] = 1.0f; fMoreColor[13] = 1.0f; fMoreColor[14] = 0.0f; fMoreColor[15] = 1.0f; fMoreColor[16] = 0.0f; fMoreColor[17] = 1.0f; fMoreColor[18] = 1.0f; fMoreColor[19] = 1.0f; fMoreColor[20] = 1.0f; fMoreColor[21] = 1.0f; fMoreColor[22] = 1.0f; fMoreColor[23] = 1.0f; fMoreColor[24] = 1.0f; fMoreColor[25] = 1.0f; fMoreColor[26] = 1.0f; fMoreColor[27] = 1.0f; fMoreColor[28] = 0.0f; fMoreColor[29] = 0.0f; fMoreColor[30] = 1.0f; fMoreColor[31] = 1.0f; fMoreColor[32] = 0.0f; fMoreColor[33] = 0.2f; fMoreColor[34] = -0.7f; fMoreColor[35] = 0.0f; glGenVertexArrays(4, uiVAO); // Generate two VAOs, one for triangle and one for quad glGenBuffers(8, uiVBO); // And four VBOs // Setup whole triangle glBindVertexArray(uiVAO[0]); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[0]); glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangle, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[1]); glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangleColor, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); // Setup whole quad glBindVertexArray(uiVAO[1]); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[2]); glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), fQuad, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[3]); glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), fQuadColor, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); // Setup whole quad glBindVertexArray(uiVAO[2]); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[4]); glBufferData(GL_ARRAY_BUFFER, 54 * sizeof(float), fDuck, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[5]); glBufferData(GL_ARRAY_BUFFER, 54 * sizeof(float), fDuckColor, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); // Setup whole quad glBindVertexArray(uiVAO[3]); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[6]); glBufferData(GL_ARRAY_BUFFER, 36 * sizeof(float), fMore, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, uiVBO[7]); glBufferData(GL_ARRAY_BUFFER, 36 * sizeof(float), fMoreColor, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); // Load shaders and create shader program shVertex.LoadShader("data\\shaders\\shader.vert", GL_VERTEX_SHADER); shFragment.LoadShader("data\\shaders\\shader.frag", GL_FRAGMENT_SHADER); spMain.CreateProgram(); spMain.AddShaderToProgram(&shVertex); spMain.AddShaderToProgram(&shFragment); spMain.LinkProgram(); spMain.UseProgram(); }
void CSDLOpenGLWindow::InitScene() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); vboSceneObjects.CreateVBO(); glGenVertexArrays(2, uiVAOs); // Create one VAO glBindVertexArray(uiVAOs[0]); vboSceneObjects.BindVBO(); // Add cube to VBO for (int i = 0; i < 36; i++) { vboSceneObjects.AddData(&vCubeVertices[i], sizeof(glm::vec3)); vboSceneObjects.AddData(&vCubeTexCoords[i % 6], sizeof(glm::vec2)); } // Add ground to VBO for (int i = 0; i < 6; i++) { vboSceneObjects.AddData(&vGround[i], sizeof(glm::vec3)); vCubeTexCoords[i] *= 10.0f; vboSceneObjects.AddData(&vCubeTexCoords[i % 6], sizeof(glm::vec2)); } vboSceneObjects.UploadDataToGPU(GL_STATIC_DRAW); // Vertex positions glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3) + sizeof(glm::vec2), 0); // Texture coordinates glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec3) + sizeof(glm::vec2), (void*)sizeof(glm::vec3)); // Setup another VAO for untextured objects glBindVertexArray(uiVAOs[1]); // Here enable only first vertex attribute - position (no texture coordinates) glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3) + sizeof(glm::vec2), 0); // Load shaders and create shader programs shVertexTex.LoadShader("data\\shaders\\tut07\\shaderTex.vert", GL_VERTEX_SHADER); shFragmentTex.LoadShader("data\\shaders\\tut07\\shaderTex.frag", GL_FRAGMENT_SHADER); shVertexCol.LoadShader("data\\shaders\\tut07\\shaderCol.vert", GL_VERTEX_SHADER); shFragmentCol.LoadShader("data\\shaders\\tut07\\shaderCol.frag", GL_FRAGMENT_SHADER); spTextured.CreateProgram(); spTextured.AddShaderToProgram(&shVertexTex); spTextured.AddShaderToProgram(&shFragmentTex); spTextured.LinkProgram(); spColored.CreateProgram(); spColored.AddShaderToProgram(&shVertexCol); spColored.AddShaderToProgram(&shFragmentCol); spColored.LinkProgram(); tBlueIce.LoadTexture2D("data\\textures\\blueice.jpg", true); tBlueIce.SetFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP); tBox.LoadTexture2D("data\\textures\\box.jpg", true); tBox.SetFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP); glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glClearColor(0.2f, 0.32f, 0.5f, 1.0f); cCamera = CWalkingCamera(glm::vec3(0.0f, 0.0f, -20.0f), glm::vec3(0.0f, 0.0f, -19.0f), glm::vec3(0.0f, 1.0f, 0.0f), 15.0f); }
void CSDLOpenGLWindow::InitScene() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); vboSceneObjects.CreateVBO(); glGenVertexArrays(1, uiVAOs); // Create one VAO glBindVertexArray(uiVAOs[0]); vboSceneObjects.BindVBO(); // Add cube to VBO for (int i = 0; i < 36; i++) { vboSceneObjects.AddData(&vCubeVertices[i], sizeof(glm::vec3)); vboSceneObjects.AddData(&vCubeTexCoords[i % 6], sizeof(glm::vec2)); vboSceneObjects.AddData(&vCubeNormals[i / 6], sizeof(glm::vec3)); } // Add ground to VBO for (int i = 0; i < 6; i++) { vboSceneObjects.AddData(&vGround[i], sizeof(glm::vec3)); vCubeTexCoords[i] *= 10.0f; vboSceneObjects.AddData(&vCubeTexCoords[i % 6], sizeof(glm::vec2)); glm::vec3 vGroundNormal(0.0f, 1.0f, 0.0f); vboSceneObjects.AddData(&vGroundNormal, sizeof(glm::vec3)); } // Add torus to VBO and remember number of faces (triangles) of this torus iTorusFaces1 = GenerateTorus(vboSceneObjects, 7.0f, 2.0f, 20, 20); // Add sun torus to VBO iTorusFaces2 = GenerateTorus(vboSceneObjects, 10.0f, 6.0f, 10, 10); vboSceneObjects.UploadDataToGPU(GL_STATIC_DRAW); // Vertex positions glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 2 * sizeof(glm::vec3) + sizeof(glm::vec2), 0); // Texture coordinates glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(glm::vec3) + sizeof(glm::vec2), (void*)sizeof(glm::vec3)); // Normal vectors glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 2 * sizeof(glm::vec3) + sizeof(glm::vec2), (void*)(sizeof(glm::vec3) + sizeof(glm::vec2))); // Load shaders and create shader programs shVertex.LoadShader("data\\shaders\\tut08\\shader.vert", GL_VERTEX_SHADER); shFragment.LoadShader("data\\shaders\\tut08\\shader.frag", GL_FRAGMENT_SHADER); shDirLight.LoadShader("data\\shaders\\common\\directionalLight.frag", GL_FRAGMENT_SHADER); spDirectionalLight.CreateProgram(); spDirectionalLight.AddShaderToProgram(&shVertex); spDirectionalLight.AddShaderToProgram(&shFragment); spDirectionalLight.AddShaderToProgram(&shDirLight); spDirectionalLight.LinkProgram(); // Load textures std::string sTextureNames[] = { "ground.jpg", "box.jpg", "rust.jpg", "sun.jpg" }; for (int i = 0; i < 4; i++) { tTextures[i].LoadTexture2D("data\\textures\\" + sTextureNames[i], true); tTextures[i].SetFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP); } glEnable(GL_DEPTH_TEST); glClearDepth(1.0); cCamera = CWalkingCamera(glm::vec3(0.0f, 3.0f, -20.0f), glm::vec3(0.0f, 3.0f, -19.0f), glm::vec3(0.0f, 1.0f, 0.0f), 35.0f); }
// Initialisation: This method only runs once at startup void Game::Initialise() { // Set the clear colour and depth glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); /// Create objects m_pCamera = new CCamera; m_pSkybox = new CSkybox; m_pShaderPrograms = new vector <CShaderProgram *>; m_pPlanarTerrain = new CPlane; m_pFtFont = new CFreeTypeFont; m_pBarrelMesh = new COpenAssetImportMesh; m_pHorseMesh = new COpenAssetImportMesh; m_pSphere = new CSphere; m_pAudio = new CAudio; m_pGrid = new CGrid; RECT dimensions = m_gameWindow.GetDimensions(); int width = dimensions.right - dimensions.left; int height = dimensions.bottom - dimensions.top; // Set the orthographic and perspective projection matrices based on the image size m_pCamera->SetOrthographicProjectionMatrix(width, height); m_pCamera->SetPerspectiveProjectionMatrix(45.0f, (float) width / (float) height, 0.5f, 5000.0f); // Load shaders vector<CShader> shShaders; vector<string> sShaderFileNames; sShaderFileNames.push_back("mainShader.vert"); sShaderFileNames.push_back("mainShader.frag"); sShaderFileNames.push_back("textShader.vert"); sShaderFileNames.push_back("textShader.frag"); sShaderFileNames.push_back("sphereShader.vert"); sShaderFileNames.push_back("sphereShader.frag"); for (int i = 0; i < (int) sShaderFileNames.size(); i++) { string sExt = sShaderFileNames[i].substr((int) sShaderFileNames[i].size()-4, 4); int iShaderType; if (sExt == "vert") iShaderType = GL_VERTEX_SHADER; else if (sExt == "frag") iShaderType = GL_FRAGMENT_SHADER; else if (sExt == "geom") iShaderType = GL_GEOMETRY_SHADER; else if (sExt == "tcnl") iShaderType = GL_TESS_CONTROL_SHADER; else iShaderType = GL_TESS_EVALUATION_SHADER; CShader shader; shader.LoadShader("resources\\shaders\\"+sShaderFileNames[i], iShaderType); shShaders.push_back(shader); } // Create the main shader program CShaderProgram *pMainProgram = new CShaderProgram; pMainProgram->CreateProgram(); pMainProgram->AddShaderToProgram(&shShaders[0]); pMainProgram->AddShaderToProgram(&shShaders[1]); pMainProgram->LinkProgram(); m_pShaderPrograms->push_back(pMainProgram); // Create a shader program for fonts CShaderProgram *pFontProgram = new CShaderProgram; pFontProgram->CreateProgram(); pFontProgram->AddShaderToProgram(&shShaders[2]); pFontProgram->AddShaderToProgram(&shShaders[3]); pFontProgram->LinkProgram(); m_pShaderPrograms->push_back(pFontProgram); // Create the sphere shader program CShaderProgram *pSphereProgram = new CShaderProgram; pSphereProgram->CreateProgram(); pSphereProgram->AddShaderToProgram(&shShaders[4]); pSphereProgram->AddShaderToProgram(&shShaders[5]); pSphereProgram->LinkProgram(); m_pShaderPrograms->push_back(pSphereProgram); // Create the skybox // Skybox downloaded from http://www.akimbo.in/forum/viewtopic.php?f=10&t=9 m_pSkybox->Create(2500.0f); // Create the planar terrain m_pPlanarTerrain->Create("resources\\textures\\", "grassfloor01.jpg", 2000.0f, 2000.0f, 50.0f); // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013 m_pFtFont->LoadSystemFont("arial.ttf", 32); m_pFtFont->SetShaderProgram(pFontProgram); // Load some meshes in OBJ format m_pBarrelMesh->Load("resources\\models\\Barrel\\Barrel02.obj"); // Downloaded from http://www.psionicgames.com/?page_id=24 on 24 Jan 2013 m_pHorseMesh->Load("resources\\models\\Horse\\Horse2.obj"); // Downloaded from http://opengameart.org/content/horse-lowpoly on 24 Jan 2013 // Create a sphere m_pSphere->Create("resources\\textures\\", "dirtpile01.jpg", 25, 25); // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013 glEnable(GL_CULL_FACE); // Initialise audio and play background music m_pAudio->Initialise(); m_pAudio->LoadEventSound("Resources\\Audio\\Boing.wav"); // Royalty free sound from freesound.org m_pAudio->LoadMusicStream("Resources\\Audio\\DST-Garote.mp3"); // Royalty free music from http://www.nosoapradio.us/ m_pAudio->PlayMusicStream(); // Create the grid m_pGrid->Create(500, 500, 15); }