本文整理汇总了C++中GLSLShader::Use方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLShader::Use方法的具体用法?C++ GLSLShader::Use怎么用?C++ GLSLShader::Use使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLShader
的用法示例。
在下文中一共展示了GLSLShader::Use方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawScene
//scene rendering function
void DrawScene(const glm::mat4& View, const glm::mat4& Proj ) {
GL_CHECK_ERRORS
//bind the current shader
shader.Use();
//bind the cube vertex array object
glBindVertexArray(cubeVAOID); {
//set the cube's transform
glm::mat4 T = glm::translate(glm::mat4(1), glm::vec3(-1,1,0));
glm::mat4 M = T; //Model matrix
glm::mat4 MV = View*M; //ModelView matrix
glm::mat4 MVP = Proj*MV; //combined ModelView Projection matrix
//pass shader uniforms
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(shader("MV"), 1, GL_FALSE, glm::value_ptr(MV));
glUniformMatrix3fv(shader("N"), 1, GL_FALSE, glm::value_ptr(glm::inverseTranspose(glm::mat3(MV))));
glUniform3f(shader("diffuse_color"), 1.0f,0.0f,0.0f);
glUniform3fv(shader("light_position"),1, &(lightPosOS.x));
//draw triangles
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
}
//bind the sphere vertex array object
glBindVertexArray(sphereVAOID); {
//set the sphere's transform
glm::mat4 T = glm::translate(glm::mat4(1), glm::vec3(1,1,0));
glm::mat4 M = T;
glm::mat4 MV = View*M;
glm::mat4 MVP = Proj*MV;
//pass shader uniforms
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(shader("MV"), 1, GL_FALSE, glm::value_ptr(MV));
glUniformMatrix3fv(shader("N"), 1, GL_FALSE, glm::value_ptr(glm::inverseTranspose(glm::mat3(MV))));
glUniform3f(shader("diffuse_color"), 0.0f, 0.0f, 1.0f);
//draw triangles
glDrawElements(GL_TRIANGLES, totalSphereTriangles, GL_UNSIGNED_SHORT, 0);
}
//unbind shader
shader.UnUse();
GL_CHECK_ERRORS
//bind light gizmo vertex array object
glBindVertexArray(lightVAOID); {
//set light's transform
glm::mat4 T = glm::translate(glm::mat4(1), lightPosOS);
//bind shader and draw 3 lines
pFlatShader->Use();
glUniformMatrix4fv((*pFlatShader)("MVP"), 1, GL_FALSE, glm::value_ptr(Proj*View*T));
glDrawArrays(GL_LINES, 0, 6);
//unbind shader
pFlatShader->UnUse();
}
//unbind the vertex array object
glBindVertexArray(0);
//render grid object
grid->Render(glm::value_ptr(Proj*View));
}
示例2: OnInit
//.........这里部分代码省略.........
//determine the image format
GLenum format = GL_RGBA;
switch(channels) {
case 2: format = GL_RG32UI; break;
case 3: format = GL_RGB; break;
case 4: format = GL_RGBA; break;
}
GLuint id = 0;
//generate new texture id
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
//set texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//allocate the texture
glTexImage2D(GL_TEXTURE_2D, 0, format, texture_width, texture_height, 0, format, GL_UNSIGNED_BYTE, pData);
//delete the SOIL image data
SOIL_free_image_data(pData);
//store the texture id into the material map. Refer to the texture by name
//will give us its OpenGL texture id
materialMap[filename] = id ;
}
GL_CHECK_ERRORS
//setup shaders
flatShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/flat.vert");
flatShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/flat.frag");
//compile and link flat shader
flatShader.CreateAndLinkProgram();
flatShader.Use();
//add shader attributes and uniforms
flatShader.AddAttribute("vVertex");
flatShader.AddUniform("MVP");
flatShader.UnUse();
//For the skinning vertex shader, we pass the Bones array dynamcially
//since we may not know the total number of bones in the model at compile
//time. Since the GLSL arrays have to be a compile time constant, we
//dynamically generate the shader string to add the uniform in the shader.
//To achieve this, we overload the GLSLShader::LoadFromFile function with
//a thid parameter, the string we want to add before the shader main function.
stringstream str( ios_base::app | ios_base::out);
str<<"\nconst int NUM_BONES="<<skeleton.size()*2<<";"<<endl;
str<<"uniform vec4 Bones[NUM_BONES];"<<endl;
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/shader.vert", str.str());
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/shader.frag");
//compile and link shader
shader.CreateAndLinkProgram();
shader.Use();
//add shader attributes and uniforms
shader.AddAttribute("vVertex");
shader.AddAttribute("vNormal");
shader.AddAttribute("vUV");
shader.AddAttribute("vBlendWeights");
shader.AddAttribute("viBlendIndices");
shader.AddUniform("Bones");
shader.AddUniform("MV");
shader.AddUniform("N");
shader.AddUniform("P");
shader.AddUniform("textureMap");
示例3: OnInit
//OpenGL initialization
void OnInit() {
GL_CHECK_ERRORS
//load heightmap shader
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/shader.vert");
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/shader.frag");
//compile and link shader
shader.CreateAndLinkProgram();
shader.Use();
//add attributes and uniforms
shader.AddAttribute("vVertex");
shader.AddUniform("heightMapTexture");
shader.AddUniform("scale");
shader.AddUniform("half_scale");
shader.AddUniform("HALF_TERRAIN_SIZE");
shader.AddUniform("MVP");
//set values of constant uniforms as initialization
glUniform1i(shader("heightMapTexture"), 0);
glUniform2i(shader("HALF_TERRAIN_SIZE"), TERRAIN_WIDTH>>1, TERRAIN_DEPTH>>1);
glUniform1f(shader("scale"), scale);
glUniform1f(shader("half_scale"), half_scale);
shader.UnUse();
GL_CHECK_ERRORS
//fill indices array
GLuint* id=&indices[0];
int i=0, j=0;
//setup vertices
int count = 0;
//fill terrain vertices
for( j=0;j<TERRAIN_DEPTH;j++) {
for( i=0;i<TERRAIN_WIDTH;i++) {
vertices[count] = glm::vec3( (float(i)/(TERRAIN_WIDTH-1)),
0,
(float(j)/(TERRAIN_DEPTH-1)));
count++;
}
}
//fill terrain indices
for (i = 0; i < TERRAIN_DEPTH-1; i++) {
for (j = 0; j < TERRAIN_WIDTH-1; j++) {
int i0 = j+ i*TERRAIN_WIDTH;
int i1 = i0+1;
int i2 = i0+TERRAIN_WIDTH;
int i3 = i2+1;
*id++ = i0;
*id++ = i2;
*id++ = i1;
*id++ = i1;
*id++ = i2;
*id++ = i3;
}
}
GL_CHECK_ERRORS
//setup terrain vertex array and vertex buffer objects
glGenVertexArrays(1, &vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindVertexArray(vaoID);
glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID);
//pass terrain vertices to buffer object
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attribute array for position
glEnableVertexAttribArray(shader["vVertex"]);
glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,0,0);
GL_CHECK_ERRORS
//pass the terrain indices array to element array buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//load the heightmap texture using SOIL
int texture_width = 0, texture_height = 0, channels=0;
GLubyte* pData = SOIL_load_image(filename.c_str(), &texture_width, &texture_height, &channels, SOIL_LOAD_L);
//vertically flip the heightmap image on Y axis since it is inverted
for( j = 0; j*2 < texture_height; ++j )
{
int index1 = j * texture_width ;
int index2 = (texture_height - 1 - j) * texture_width ;
for( i = texture_width ; i > 0; --i )
{
GLubyte temp = pData[index1];
pData[index1] = pData[index2];
pData[index2] = temp;
++index1;
++index2;
}
}
//.........这里部分代码省略.........
示例4: OnInit
//OpenGL initialization
void OnInit() {
//load the per-fragment point light shader
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/PointLight.vert");
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/PointLight.frag");
//compile and link shader
shader.CreateAndLinkProgram();
shader.Use();
//add attributes and uniforms
shader.AddAttribute("vVertex");
shader.AddAttribute("vNormal");
shader.AddUniform("MVP");
shader.AddUniform("MV");
shader.AddUniform("N");
shader.AddUniform("light_position");
shader.AddUniform("diffuse_color");
shader.UnUse();
GL_CHECK_ERRORS
//setup sphere geometry
CreateSphere(1.0f,10,10, vertices, indices);
//setup sphere vao and vbo stuff
glGenVertexArrays(1, &sphereVAOID);
glGenBuffers(1, &sphereVerticesVBO);
glGenBuffers(1, &sphereIndicesVBO);
glBindVertexArray(sphereVAOID);
glBindBuffer (GL_ARRAY_BUFFER, sphereVerticesVBO);
//pass vertices to the buffer object
glBufferData (GL_ARRAY_BUFFER, vertices.size()*sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attribute array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),0);
GL_CHECK_ERRORS
//enable vertex attribute array for normal
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, normal)));
GL_CHECK_ERRORS
//pass sphere indices to element array buffer
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, sphereIndicesVBO);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(GLushort), &indices[0], GL_STATIC_DRAW);
//store the total number of sphere triangles
totalSphereTriangles = indices.size();
//clear the vertices and indices vectors as we will reuse them
//for cubes
vertices.clear();
indices.clear();
//setup cube geometry
CreateCube(2,vertices, indices);
//setup cube vao and vbo stuff
glGenVertexArrays(1, &cubeVAOID);
glGenBuffers(1, &cubeVerticesVBO);
glGenBuffers(1, &cubeIndicesVBO);
glBindVertexArray(cubeVAOID);
glBindBuffer (GL_ARRAY_BUFFER, cubeVerticesVBO);
//pass vertices to the buffer object
glBufferData (GL_ARRAY_BUFFER, vertices.size()*sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attribute array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),0);
GL_CHECK_ERRORS
//enable vertex attribute array for normal
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, normal)));
GL_CHECK_ERRORS
//pass cube indices to element array buffer
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, cubeIndicesVBO);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(GLushort), &indices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//setup vao and vbo stuff for the light position crosshair
glm::vec3 crossHairVertices[6];
crossHairVertices[0] = glm::vec3(-0.5f,0,0);
crossHairVertices[1] = glm::vec3(0.5f,0,0);
crossHairVertices[2] = glm::vec3(0, -0.5f,0);
crossHairVertices[3] = glm::vec3(0, 0.5f,0);
crossHairVertices[4] = glm::vec3(0,0, -0.5f);
crossHairVertices[5] = glm::vec3(0,0, 0.5f);
//setup light gizmo vertex array and buffer object
glGenVertexArrays(1, &lightVAOID);
glGenBuffers(1, &lightVerticesVBO);
glBindVertexArray(lightVAOID);
glBindBuffer (GL_ARRAY_BUFFER, lightVerticesVBO);
//pass light crosshair gizmo vertices to buffer object
glBufferData (GL_ARRAY_BUFFER, sizeof(crossHairVertices), &(crossHairVertices[0].x), GL_STATIC_DRAW);
//.........这里部分代码省略.........
示例5: OnInit
//.........这里部分代码省略.........
GLubyte temp = pData[index1];
pData[index1] = pData[index2];
pData[index2] = temp;
++index1;
++index2;
}
}
//get the image format
GLenum format = GL_RGBA;
switch(channels) {
case 2: format = GL_RG32UI; break;
case 3: format = GL_RGB; break;
case 4: format = GL_RGBA; break;
}
//if this is the first texture, allocate the array texture
if(k==0) {
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, texture_width, texture_height, total, 0, format, GL_UNSIGNED_BYTE, NULL);
}
//modify the existing texture
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,0,0,k, texture_width, texture_height, 1, format, GL_UNSIGNED_BYTE, pData);
//release the SOIL image data
SOIL_free_image_data(pData);
}
}
GL_CHECK_ERRORS
//load flat shader
flatShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/flat.vert");
flatShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/flat.frag");
//compile and link shader
flatShader.CreateAndLinkProgram();
flatShader.Use();
//add attribute and uniform
flatShader.AddAttribute("vVertex");
flatShader.AddUniform("MVP");
flatShader.UnUse();
//load raytracing shader
raytraceShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/raytracer.vert");
raytraceShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/raytracer.frag");
//compile and link shader
raytraceShader.CreateAndLinkProgram();
raytraceShader.Use();
//add attribute and uniform
raytraceShader.AddAttribute("vVertex");
raytraceShader.AddUniform("eyePos");
raytraceShader.AddUniform("invMVP");
raytraceShader.AddUniform("light_position");
raytraceShader.AddUniform("backgroundColor");
raytraceShader.AddUniform("aabb.min");
raytraceShader.AddUniform("aabb.max");
raytraceShader.AddUniform("vertex_positions");
raytraceShader.AddUniform("triangles_list");
raytraceShader.AddUniform("VERTEX_TEXTURE_SIZE");
raytraceShader.AddUniform("TRIANGLE_TEXTURE_SIZE");
//set values of constant uniforms as initialization
glUniform1f(raytraceShader("VERTEX_TEXTURE_SIZE"), (float)vertices2.size());
glUniform1f(raytraceShader("TRIANGLE_TEXTURE_SIZE"), (float)indices2.size()/4);
glUniform3fv(raytraceShader("aabb.min"),1, glm::value_ptr(aabb.min));
glUniform3fv(raytraceShader("aabb.max"),1, glm::value_ptr(aabb.max));
glUniform4fv(raytraceShader("backgroundColor"),1, glm::value_ptr(bg));
glUniform1i(raytraceShader("vertex_positions"), 1);
glUniform1i(raytraceShader("triangles_list"), 2);
示例6: RenderGPU_TF
//update and rendering of cloth particles
void RenderGPU_TF() {
CHECK_GL_ERRORS
//set the cloth vertex shader
massSpringShader.Use();
CHECK_GL_ERRORS
//pass shader uniforms
glUniformMatrix4fv(massSpringShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));
CHECK_GL_ERRORS
//run the iteration loop
for(int i=0;i<NUM_ITER;i++) {
//set the buffer texture for current position
glActiveTexture( GL_TEXTURE0);
glBindTexture( GL_TEXTURE_BUFFER, texPosID[writeID]);
//set the buffer texture for previous position
glActiveTexture( GL_TEXTURE1);
glBindTexture( GL_TEXTURE_BUFFER, texPrePosID[writeID]);
//set the update vertex array object
glBindVertexArray( vaoUpdateID[writeID]);
//bind transform feedback buffers
//index 0 -> current position
//index 1 -> previous position
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vboID_Pos[readID]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, vboID_PrePos[readID]);
// disable rasterization
glEnable(GL_RASTERIZER_DISCARD);
//run hardware timer query
glBeginQuery(GL_TIME_ELAPSED,t_query);
//initiate transform feedback
glBeginTransformFeedback(GL_POINTS);
//render points, this call pushes all attributes to GPU
glDrawArrays(GL_POINTS, 0, total_points);
//end transform feedback
glEndTransformFeedback();
//end timer query
glEndQuery(GL_TIME_ELAPSED);
glFlush();
//enable rasterizer
glDisable(GL_RASTERIZER_DISCARD);
//swap read/write pathways
int tmp = readID;
readID=writeID;
writeID = tmp;
}
CHECK_GL_ERRORS
// get the query result
glGetQueryObjectui64v(t_query, GL_QUERY_RESULT, &elapsed_time);
//get the transform feedback time
delta_time = elapsed_time / 1000000.0f;
//remove the cloth vertex shader
massSpringShader.UnUse();
CHECK_GL_ERRORS;
//bind the render vertex array object
glBindVertexArray(vaoRenderID[writeID]);
//disable depth test
glDisable(GL_DEPTH_TEST);
//set the render shader
renderShader.Use();
//set the shader uniform
glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));
//draw the cloth geometry
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT,0);
//remove render shader
renderShader.UnUse();
//enable depth test
glEnable(GL_DEPTH_TEST);
//if we want to display masses
if(bDisplayMasses) {
//set the particle shader
particleShader.Use();
//set shader uniforms
glUniform1i(particleShader("selected_index"), selected_index);
glUniformMatrix4fv(particleShader("MV"), 1, GL_FALSE, glm::value_ptr(mMV));
glUniformMatrix4fv(particleShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));
//draw the masses last
glDrawArrays(GL_POINTS, 0, total_points);
//this also renders particles
//glDrawTransformFeedbackStream(GL_POINTS, tfID, 0);
//remove the particle shader
particleShader.UnUse();
}
//remove the currently bound vertex array object
glBindVertexArray( 0);
CHECK_GL_ERRORS
}
示例7: OnInit
//OpenGL initialization
void OnInit() {
//set the polygon mode to render lines
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
GL_CHECK_ERRORS
//load shader
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/shader.vert");
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/shader.frag");
//compile and link shader
shader.CreateAndLinkProgram();
shader.Use();
//add shader attribute and uniforms
shader.AddAttribute("vVertex");
shader.AddUniform("MVP");
shader.AddUniform("time");
shader.UnUse();
GL_CHECK_ERRORS
//setup plane geometry
//setup plane vertices
int count = 0;
int i=0, j=0;
for( j=0;j<=NUM_Z;j++) {
for( i=0;i<=NUM_X;i++) {
vertices[count++] = glm::vec3( ((float(i)/(NUM_X-1)) *2-1)* HALF_SIZE_X, 0, ((float(j)/(NUM_Z-1))*2-1)*HALF_SIZE_Z);
}
}
//fill plane indices array
GLushort* id=&indices[0];
for (i = 0; i < NUM_Z; i++) {
for (j = 0; j < NUM_X; j++) {
int i0 = i * (NUM_X+1) + j;
int i1 = i0 + 1;
int i2 = i0 + (NUM_X+1);
int i3 = i2 + 1;
if ((j+i)%2) {
*id++ = i0; *id++ = i2; *id++ = i1;
*id++ = i1; *id++ = i2; *id++ = i3;
} else {
*id++ = i0; *id++ = i2; *id++ = i3;
*id++ = i0; *id++ = i3; *id++ = i1;
}
}
}
GL_CHECK_ERRORS
//setup plane vao and vbo stuff
glGenVertexArrays(1, &vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindVertexArray(vaoID);
glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID);
//pass plane vertices to array buffer object
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attrib array for position
glEnableVertexAttribArray(shader["vVertex"]);
glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,0,0);
GL_CHECK_ERRORS
//pass the plane indices to element array buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
cout<<"Initialization successfull"<<endl;
}
示例8: OnInit
void OnInit() {
GL_CHECK_ERRORS
//setup shader
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/shader.vert");
shader.LoadFromFile(GL_GEOMETRY_SHADER, "shaders/shader.geom");
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/shader.frag");
shader.CreateAndLinkProgram();
shader.Use();
shader.AddAttribute("vVertex");
shader.AddUniform("heightMapTexture");
shader.AddUniform("scale");
shader.AddUniform("half_scale");
shader.AddUniform("HALF_TERRAIN_SIZE");
shader.AddUniform("MVP");
glUniform1i(shader("heightMapTexture"), 0);
glUniform2i(shader("HALF_TERRAIN_SIZE"), TERRAIN_WIDTH>>1, TERRAIN_DEPTH>>1);
glUniform1f(shader("scale"), scale);
glUniform1f(shader("half_scale"), half_scale);
shader.UnUse();
GL_CHECK_ERRORS
//setup geometry
//fill indices array
GLuint* id=&indices[0];
int i=0, j=0;
//setup vertices
int count = 0;
for( j=0;j<TERRAIN_DEPTH;j++) {
for( i=0;i<TERRAIN_WIDTH;i++) {
/*
vertices[count] = glm::vec3( ( (float(i)/(TERRAIN_WIDTH-1))*2.0f-1)*TERRAIN_HALF_WIDTH,
(pData[count]/255.0f)*scale-half_scale,
( (float(j)/(TERRAIN_DEPTH-1))*2.0-1)*TERRAIN_HALF_DEPTH);
*/
vertices[count] = glm::vec3( (float(i)/(TERRAIN_WIDTH-1)),
0,
(float(j)/(TERRAIN_DEPTH-1)));
count++;
}
}
for (i = 0; i < TERRAIN_DEPTH-1; i++) {
for (j = 0; j < TERRAIN_WIDTH-1; j++) {
int i0 = j+ i*TERRAIN_WIDTH;
int i1 = i0+1;
int i2 = i0+TERRAIN_WIDTH;
int i3 = i2+1;
*id++ = i0;
*id++ = i2;
*id++ = i1;
*id++ = i1;
*id++ = i2;
*id++ = i3;
}
}
GL_CHECK_ERRORS
//setup vao and vbo stuff
glGenVertexArrays(1, &vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindVertexArray(vaoID);
glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID);
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
glEnableVertexAttribArray(shader["vVertex"]);
glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,0,0);
GL_CHECK_ERRORS
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//load the heightmap texture using SOIL
int texture_width = 0, texture_height = 0, format=0;
GLubyte* pData = SOIL_load_image(filename.c_str(), &texture_width, &texture_height, &format, SOIL_LOAD_L);
//setup OpenGL texture
glGenTextures(1, &heightMapTextureID);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, heightMapTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, texture_width, texture_height, 0, GL_RED, GL_UNSIGNED_BYTE, pData);
free(pData);
GL_CHECK_ERRORS
//.........这里部分代码省略.........
示例9: OnInit
//OpenGL initialization
void OnInit() {
//get the OBJ mesh path
std::string mesh_path = mesh_filename.substr(0, mesh_filename.find_last_of("/")+1);
//load the OBJ model
if(!obj.Load(mesh_filename.c_str(), meshes, vertices, indices, materials)) {
cout<<"Cannot load the obj mesh"<<endl;
exit(EXIT_FAILURE);
}
GL_CHECK_ERRORS
//load material textures
for(size_t k=0;k<materials.size();k++) {
//if the diffuse texture name is not empty
if(materials[k]->map_Kd != "") {
GLuint id = 0;
//generate a new OpenGL texture
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
int texture_width = 0, texture_height = 0, channels=0;
const string& filename = materials[k]->map_Kd;
std::string full_filename = mesh_path;
full_filename.append(filename);
//use SOIL to load the texture
GLubyte* pData = SOIL_load_image(full_filename.c_str(), &texture_width, &texture_height, &channels, SOIL_LOAD_AUTO);
if(pData == NULL) {
cerr<<"Cannot load image: "<<full_filename.c_str()<<endl;
exit(EXIT_FAILURE);
}
//Flip the image on Y axis
int i,j;
for( j = 0; j*2 < texture_height; ++j )
{
int index1 = j * texture_width * channels;
int index2 = (texture_height - 1 - j) * texture_width * channels;
for( i = texture_width * channels; i > 0; --i )
{
GLubyte temp = pData[index1];
pData[index1] = pData[index2];
pData[index2] = temp;
++index1;
++index2;
}
}
//get the image format
GLenum format = GL_RGBA;
switch(channels) {
case 2: format = GL_RG32UI; break;
case 3: format = GL_RGB; break;
case 4: format = GL_RGBA; break;
}
//allocate the texture
glTexImage2D(GL_TEXTURE_2D, 0, format, texture_width, texture_height, 0, format, GL_UNSIGNED_BYTE, pData);
//release the SOIL image data
SOIL_free_image_data(pData);
//add the texture id to a vector
textures.push_back(id);
}
}
GL_CHECK_ERRORS
//load the flat shader
flatShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/flat.vert");
flatShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/flat.frag");
//compile and link shader
flatShader.CreateAndLinkProgram();
flatShader.Use();
//add attribute and uniform
flatShader.AddAttribute("vVertex");
flatShader.AddUniform("MVP");
flatShader.UnUse();
//load spherical harmonics shader
sh_shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/sh_shader.vert");
sh_shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/sh_shader.frag");
//compile and link shader
sh_shader.CreateAndLinkProgram();
sh_shader.Use();
//add attribute and uniform
sh_shader.AddAttribute("vVertex");
sh_shader.AddAttribute("vNormal");
sh_shader.AddAttribute("vUV");
sh_shader.AddUniform("MV");
sh_shader.AddUniform("N");
sh_shader.AddUniform("P");
sh_shader.AddUniform("textureMap");
sh_shader.AddUniform("light_position");
sh_shader.AddUniform("useDefault");
sh_shader.AddUniform("diffuse_color");
//.........这里部分代码省略.........
示例10: OnRender
//display callback function
void OnRender() {
//clear the colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//set the viewing transformation
glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
glm::mat4 Rx = glm::rotate(T, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 MV = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
//bind the mesh vertex array object
glBindVertexArray(vaoID); {
//bind the current shader
pCurrentShader->Use();
//pass the shader uniforms
glUniformMatrix4fv((*pCurrentShader)("MV"), 1, GL_FALSE, glm::value_ptr(MV));
glUniformMatrix3fv((*pCurrentShader)("N"), 1, GL_FALSE, glm::value_ptr(glm::inverseTranspose(glm::mat3(MV))));
glUniformMatrix4fv((*pCurrentShader)("P"), 1, GL_FALSE, glm::value_ptr(P));
glUniform3fv((*pCurrentShader)("light_position"),1, &(lightPosOS.x));
//loop through all materials
for(size_t i=0;i<materials.size();i++) {
Material* pMat = materials[i];
//if material texture filename is not empty
if(pMat->map_Kd !="") {
glUniform1f((*pCurrentShader)("useDefault"), 0.0);
//get the currently bound texture and check if the current texture ID
//is not equal, if so bind the new texture
GLint whichID[1];
glGetIntegerv(GL_TEXTURE_BINDING_2D, whichID);
if(whichID[0] != textures[i])
glBindTexture(GL_TEXTURE_2D, textures[i]);
}
else
//otherwise we have no texture, we use a defaul colour
glUniform1f((*pCurrentShader)("useDefault"), 1.0);
//if we have a single material, we render the whole mesh in a single call
if(materials.size()==1)
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, 0);
else
//otherwise we render the submesh
glDrawElements(GL_TRIANGLES, pMat->count, GL_UNSIGNED_SHORT, (const GLvoid*)(&indices[pMat->offset]));
}
//unbind the current shader
pCurrentShader->UnUse();
}
//draw the light gizmo
glBindVertexArray(lightVAOID); {
//set the modelling transform for the light crosshair gizmo
glm::mat4 T = glm::translate(glm::mat4(1), lightPosOS);
//bind the shader
flatShader.Use();
//set shader uniforms and draw lines
glUniformMatrix4fv(flatShader("MVP"), 1, GL_FALSE, glm::value_ptr(P*MV*T));
glDrawArrays(GL_LINES, 0, 6);
//unbind the shader
flatShader.UnUse();
}
//swap front and back buffers to show the rendered result
glutSwapBuffers();
}
示例11: OnInit
//OpenGL initialization function
void OnInit() {
GL_CHECK_ERRORS
//create a uniform grid of size 20x20 in XZ plane
grid = new CGrid(20,20);
GL_CHECK_ERRORS
//create a new TetrahedraMarcher instance
marcher = new TetrahedraMarcher();
//set the volume dataset dimensions
marcher->SetVolumeDimensions(256,256,256);
//load the volume dataset
marcher->LoadVolume(volume_file);
//set the isosurface value
marcher->SetIsosurfaceValue(48);
//set the number of sampling voxels
marcher->SetNumSamplingVoxels(128,128,128);
//begin tetrahedra marching
marcher->MarchVolume();
//setup the volume marcher vertex array object and vertex buffer object
glGenVertexArrays(1, &volumeMarcherVAO);
glGenBuffers(1, &volumeMarcherVBO);
glBindVertexArray(volumeMarcherVAO);
glBindBuffer (GL_ARRAY_BUFFER, volumeMarcherVBO);
//pass the obtained vertices from the tetrahedra marcher and pass to the
//buffer object memory
glBufferData (GL_ARRAY_BUFFER, marcher->GetTotalVertices()*sizeof(Vertex), marcher->GetVertexPointer(), GL_STATIC_DRAW);
//enable vertex attribute array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),0);
//enable vertex attribute array for normals
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),(const GLvoid*)offsetof(Vertex, normal));
GL_CHECK_ERRORS
//load the shader
shader.LoadFromFile(GL_VERTEX_SHADER, "shaders/marcher.vert");
shader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/marcher.frag");
//compile and link the shader program
shader.CreateAndLinkProgram();
shader.Use();
//add attribute and uniform
shader.AddAttribute("vVertex");
shader.AddAttribute("vNormal");
shader.AddUniform("MVP");
shader.UnUse();
GL_CHECK_ERRORS
//set the background colour
glClearColor(bg.r, bg.g, bg.b, bg.a);
//enable depth test and culling
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
cout<<"Initialization successfull"<<endl;
}
示例12: OnRender
//display callback function
void OnRender() {
GL_CHECK_ERRORS
//camera transformation
glm::mat4 Tr = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
glm::mat4 Rx = glm::rotate(Tr, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 MV = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
//clear colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//get the combined modelview projection matrix
glm::mat4 MVP = P*MV;
//if we want to use depth peeling
if(bShowDepthPeeling) {
//bind the colour blending FBO
glBindFramebuffer(GL_FRAMEBUFFER, colorBlenderFBOID);
//set the first colour attachment as the draw buffer
glDrawBuffer(GL_COLOR_ATTACHMENT0);
//clear the colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// 1. In the first pass, we render normally with depth test enabled to get the nearest surface
glEnable(GL_DEPTH_TEST);
DrawScene(MVP, cubeShader);
// 2. Depth peeling + blending pass
int numLayers = (NUM_PASSES - 1) * 2;
//for each pass
for (int layer = 1; bUseOQ || layer < numLayers; layer++) {
int currId = layer % 2;
int prevId = 1 - currId;
//bind the current FBO
glBindFramebuffer(GL_FRAMEBUFFER, fbo[currId]);
//set the first colour attachment as draw buffer
glDrawBuffer(GL_COLOR_ATTACHMENT0);
//set clear colour to black
glClearColor(0, 0, 0, 0);
//clear the colour and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//disbale blending and depth testing
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
//if we want to use occlusion query, we initiate it
if (bUseOQ) {
glBeginQuery(GL_SAMPLES_PASSED_ARB, queryId);
}
GL_CHECK_ERRORS
//bind the depth texture from the previous step
glBindTexture(GL_TEXTURE_RECTANGLE, depthTexID[prevId]);
//render scene with the front to back peeling shader
DrawScene(MVP, frontPeelShader);
//if we initiated the occlusion query, we end it
if (bUseOQ) {
glEndQuery(GL_SAMPLES_PASSED_ARB);
}
GL_CHECK_ERRORS
//bind the colour blender FBO
glBindFramebuffer(GL_FRAMEBUFFER, colorBlenderFBOID);
//render to its first colour attachment
glDrawBuffer(GL_COLOR_ATTACHMENT0);
//enable blending but disable depth testing
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
//change the blending equation to add
glBlendEquation(GL_FUNC_ADD);
//use separate blending function
glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE,
GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
//bind the result from the previous iteration as texture
glBindTexture(GL_TEXTURE_RECTANGLE, texID[currId]);
//bind the blend shader and then draw a fullscreen quad
blendShader.Use();
DrawFullScreenQuad();
blendShader.UnUse();
//disable blending
glDisable(GL_BLEND);
GL_CHECK_ERRORS
//if we initiated the occlusion query, we get the query result
//that is the total number of samples
if (bUseOQ) {
//.........这里部分代码省略.........
示例13: OnInit
//OpenGL initialization function
void OnInit() {
GL_CHECK_ERRORS
//initialize FBO
initFBO();
//generate hardwre query
glGenQueries(1, &queryId);
//create a uniform grid of size 20x20 in XZ plane
grid = new CGrid(20,20);
GL_CHECK_ERRORS
//generate the quad vertices
glm::vec2 quadVerts[4];
quadVerts[0] = glm::vec2(0,0);
quadVerts[1] = glm::vec2(1,0);
quadVerts[2] = glm::vec2(1,1);
quadVerts[3] = glm::vec2(0,1);
//generate quad indices
GLushort quadIndices[]={ 0,1,2,0,2,3};
//generate quad vertex array and vertex buffer objects
glGenVertexArrays(1, &quadVAOID);
glGenBuffers(1, &quadVBOID);
glGenBuffers(1, &quadIndicesID);
glBindVertexArray(quadVAOID);
glBindBuffer (GL_ARRAY_BUFFER, quadVBOID);
//pass quad vertices to buffer object memory
glBufferData (GL_ARRAY_BUFFER, sizeof(quadVerts), &quadVerts[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attribute array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,0,0);
//pass the quad indices to the element array buffer
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, quadIndicesID);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(quadIndices), &quadIndices[0], GL_STATIC_DRAW);
//setup unit cube vertex array and vertex buffer objects
glGenVertexArrays(1, &cubeVAOID);
glGenBuffers(1, &cubeVBOID);
glGenBuffers(1, &cubeIndicesID);
//unit cube vertices
glm::vec3 vertices[8]={ glm::vec3(-0.5f,-0.5f,-0.5f),
glm::vec3( 0.5f,-0.5f,-0.5f),
glm::vec3( 0.5f, 0.5f,-0.5f),
glm::vec3(-0.5f, 0.5f,-0.5f),
glm::vec3(-0.5f,-0.5f, 0.5f),
glm::vec3( 0.5f,-0.5f, 0.5f),
glm::vec3( 0.5f, 0.5f, 0.5f),
glm::vec3(-0.5f, 0.5f, 0.5f)};
//unit cube indices
GLushort cubeIndices[36]={0,5,4,
5,0,1,
3,7,6,
3,6,2,
7,4,6,
6,4,5,
2,1,3,
3,1,0,
3,0,7,
7,0,4,
6,5,2,
2,5,1};
glBindVertexArray(cubeVAOID);
glBindBuffer (GL_ARRAY_BUFFER, cubeVBOID);
//pass cube vertices to buffer object memory
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &(vertices[0].x), GL_STATIC_DRAW);
GL_CHECK_ERRORS
//enable vertex attributre array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,0,0);
//pass cube indices to element array buffer
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, cubeIndicesID);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(cubeIndices), &cubeIndices[0], GL_STATIC_DRAW);
glBindVertexArray(0);
//Load the cube shader
cubeShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/cube_shader.vert");
cubeShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/cube_shader.frag");
//compile and link the shader
cubeShader.CreateAndLinkProgram();
cubeShader.Use();
//add attributes and uniforms
cubeShader.AddAttribute("vVertex");
//.........这里部分代码省略.........
示例14: OnRender
//display function
void OnRender() {
//clear the color and depth buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//setup the camera transform
glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(-center.x, -center.y, -center.z+dist));
glm::mat4 Rx = glm::rotate(T, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 MV = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
//bind the mesh vertex array object
glBindVertexArray(vaoID); {
//bind the mesh's shader
shader.Use();
//pass the shader uniforms
glUniformMatrix4fv(shader("MV"), 1, GL_FALSE, glm::value_ptr(MV));
glUniformMatrix3fv(shader("N"), 1, GL_FALSE, glm::value_ptr(glm::inverseTranspose(glm::mat3(MV))));
glUniformMatrix4fv(shader("P"), 1, GL_FALSE, glm::value_ptr(P));
glUniform3fv(shader("light_position"),1, &(lightPosOS.x));
//for all submeshes
for(size_t i=0;i<submeshes.size();i++) {
//if the material name is not empty
if(strlen(submeshes[i].materialName)>0) {
//get the OpenGL texture id from the material map using the material name
GLuint id = materialMap[material2ImageMap[submeshes[i].materialName]];
GLint whichID[1];
glGetIntegerv(GL_TEXTURE_BINDING_2D, whichID);
//if the currently bound texture id is not the same is the current texture id
//if so bind the current texture
if(whichID[0] != id)
glBindTexture(GL_TEXTURE_2D, id);
//let the shader know that we have a texture so no default colour needs to be used
glUniform1f(shader("useDefault"), 0.0);
} else {
//there is no texture in submesh, use a default colour
glUniform1f(shader("useDefault"), 1.0);
}
//draw the triangles using the submesh indices
glDrawElements(GL_TRIANGLES, submeshes[i].indices.size(), GL_UNSIGNED_INT, &submeshes[i].indices[0]);
} //end for
//unbind shader
shader.UnUse();
}
//bind the light vertex array object to show the light crosshair gizmo
glBindVertexArray(lightVAOID); {
//get the modeling transform of the light gizmo
glm::mat4 T = glm::translate(glm::mat4(1), lightPosOS);
//set the shader of the light crosshair gizmo
flatShader.Use();
//pass uniforms to the shader and render the crosshair gizmo as lines
glUniformMatrix4fv(flatShader("MVP"), 1, GL_FALSE, glm::value_ptr(P*MV*T));
glDrawArrays(GL_LINES, 0, 6);
//unbind the shader
flatShader.UnUse();
}
//swap the back buffer and front buffer to display the result on screen
glutSwapBuffers();
}
示例15: RenderScene
//.........这里部分代码省略.........
glRotatef(fPlutoRot * 3, 0.0f, 0.0f, 1.0f); // Pluto - Rotation um sich selber - simuliert Eigenrotation
gluSphere(pObj, 3.2f, 30, 17); // Pluto - Kugel zeichnen(Object, Radius, Slices, Stack)
glDisable(GL_TEXTURE_2D);
gluDeleteQuadric(pObj);
// neue Rotationsposition von Pluto (Rotationsgeschwindigkeit um die Sonne)
fPlutoRot += 0.2f;
// Rotation zurücksetzen bei 360 Grad
if (fPlutoRot >= 360.0f)
fPlutoRot = 0.0f;
glPopMatrix();
#pragma endregion
#pragma region earth
/* ----- Erde ----- */
glPushMatrix();
// quadObject erstellen und Texturkoordinaten dafür spezifizieren
pObj = gluNewQuadric();
gluQuadricTexture(pObj, GL_TRUE);
// Erden-Textur setzen
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, earthTexture);
// Rotationskoordinaten für Erde (Rotation um die Sonne)
glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f);
// Erde zeichnen
glTranslatef(500.0f, 0.0f, 0.0f); // Erde von der Sonne wegverschieben
glRotatef(270.0f, 1.0f, 0.0f, 0.0f); // dreht die Textur
glRotatef(fEarthRot * 3, 0.0f, 0.0f, 1.0f); // Erde - Rotation um sich selber - simuliert Eigenrotation
gluSphere(pObj, 16.0f, 30, 17); // Erde - Kugel zeichnen(Object, Radius, Slices, Stack)
glDisable(GL_TEXTURE_2D);
gluDeleteQuadric(pObj);
#pragma endregion
#pragma region earthMoon
/* ----- Mond ----- */
// quadObject erstellen und Texturkoordinaten dafür spezifizieren
pObj = gluNewQuadric();
gluQuadricTexture(pObj, GL_TRUE);
// Mond-Textur setzen
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, moonTexture);
glRotatef(fMoonRot, 0.0f, 1.0f, 0.0f); // Mond-Rotation um die Erde
glTranslatef(25.0f, 0.0f, 0.0f); // Mond von der Erde wegverschieben
glRotatef(270.0f, 1.0f, 0.0f, 0.0f); // dreht die Textur
glRotatef(fMoonRot * 3, 0.0f, 0.0f, 1.0f); // Mond - Rotation um sich selber - simuliert Eigenrotation
// neue Rotationsposition vom Mond
fMoonRot = 2.4f;
// Rotation zurücksetzen bei 360 Grad
if (fMoonRot >= 360.0f)
fMoonRot = 0.0f;
// Mond zeichnen
gluSphere(pObj, 4.3f, 30, 17); // Mond - Kugel zeichnen(Object, Radius, Slices, Stack)
glDisable(GL_TEXTURE_2D);
gluDeleteQuadric(pObj);
glPopMatrix();
// neue Rotationsposition von der Erde
fEarthRot += 5.0f;
// Rotation zurücksetzen bei 360 Grad
if (fEarthRot >= 360.0f)
fEarthRot = 0.0f;
glPopMatrix();
#pragma endregion
#pragma region DreiD-Model
GL_CHECK_ERRORS
// Matrizen
glm::mat4 T = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, -100.0f, -300)); // Position des Raumschiffes in der Skybox
glm::mat4 Rx = glm::rotate(T, rotation_x, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 Ry = glm::rotate(Rx, rotation_y, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 MV = glm::rotate(Ry, rotation_z, glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 MVP = P*MV;
glBindVertexArray(vaoID);
shader.Use();
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glDrawElements(GL_TRIANGLES, object.polygons_qty * 3, GL_UNSIGNED_SHORT, 0);
shader.UnUse();
glBindVertexArray(0);
#pragma endregion
// Sonnensystem anzeigen
glutSwapBuffers();
}