本文整理汇总了C++中CShader::LoadShader方法的典型用法代码示例。如果您正苦于以下问题:C++ CShader::LoadShader方法的具体用法?C++ CShader::LoadShader怎么用?C++ CShader::LoadShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CShader
的用法示例。
在下文中一共展示了CShader::LoadShader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialise
// 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);
}
示例2: InitScene
//.........这里部分代码省略.........
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();
}
示例3: InitScene
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);
}
示例4: InitScene
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);
}
示例5: Initialise
// 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();
//.........这里部分代码省略.........