本文整理汇总了C++中EsgiShader类的典型用法代码示例。如果您正苦于以下问题:C++ EsgiShader类的具体用法?C++ EsgiShader怎么用?C++ EsgiShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EsgiShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialise
bool Initialise() {
printf("Version GL : %s\n", glGetString(GL_VERSION));
printf("Pilotes GL : %s\n", glGetString(GL_RENDERER));
printf("Fabricant : %s\n", glGetString(GL_VENDOR));
printf("Version GLSL : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
GLenum status = glewInit();
g_BasicShader.LoadVertexShader("basic.vs");
g_BasicShader.LoadFragmentShader("basic.fs");
g_BasicShader.Create();
static const float triangle[] = {
-0.5f, -0.5f,
0.5f, -0.5f,
0.0f, 0.5f
};
glGenBuffers(1, &g_Object.VBO);
glBindBuffer(GL_ARRAY_BUFFER, g_Object.VBO);
// glBufferData alloue et transfort 4 * 3 octets issus du tableau triangle[]
glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
#ifdef _WIN32
wglSwapIntervalEXT(1);
#endif
return true;
}
示例2: Initialize
void Initialize()
{
printf("Version Pilote OpenGL : %s\n", glGetString(GL_VERSION));
printf("Type de GPU : %s\n", glGetString(GL_RENDERER));
printf("Fabricant : %s\n", glGetString(GL_VENDOR));
printf("Version GLSL : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
int numExtensions;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
GLenum error = glewInit();
if (error != GL_NO_ERROR) {
// TODO
}
for (int index = 0; index < numExtensions; ++index)
{
printf("Extension[%d] : %s\n", index, glGetStringi(GL_EXTENSIONS, index));
}
#ifdef _WIN32
// on coupe la synchro vertical pour voir l'effet du delta time
wglSwapIntervalEXT(0);
#endif
basicShader.LoadVertexShader("basic.vs");
basicShader.LoadFragmentShader("basic.fs");
basicShader.Create();
auto program = basicShader.GetProgram();
// UN UBO SERAIT UTILE ICI
auto basicProgram = basicShader.GetProgram();
auto blockIndex = glGetUniformBlockIndex(basicProgram, "ViewProj");
GLuint blockBinding = 1;
glGenBuffers(1, &g_Camera.UBO);
glBindBuffer(GL_UNIFORM_BUFFER, g_Camera.UBO);
//glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 2, NULL, GL_STREAM_DRAW);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(g_Camera.projectionMatrix));
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(g_Camera.viewMatrix));
glBindBufferBase(GL_UNIFORM_BUFFER, blockBinding, g_Camera.UBO);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glUniformBlockBinding(basicProgram, blockIndex, blockBinding);
previousTime = glutGet(GLUT_ELAPSED_TIME);
InitCube();
// render states par defaut
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
}
示例3: Terminate
void Terminate()
{
glDeleteVertexArrays(1, &cubeVAO);
DestroyFBO();
glDeleteBuffers(1, &cubeIBO);
glDeleteBuffers(1, &cubeVBO);
textureShader.Destroy();
basicShader.Destroy();
}
示例4: Terminate
void Terminate()
{
glDeleteBuffers(1, &g_Camera.UBO);
CleanCube();
basicShader.Destroy();
}
示例5: Terminate
void Terminate()
{
TwTerminate();
glDeleteBuffers(1, &Material::UBO);
glDeleteBuffers(1, &PointLight::UBO);
glDeleteBuffers(1, &g_Camera.UBO);
g_Spheres.shrink_to_fit();
CleanMesh(g_SphereMesh);
glDeleteTextures(3, g_Walls.textures);
CleanMesh(g_WallMesh);
g_BlinnPhongShader.Destroy();
g_AmbientShader.Destroy();
}
示例6: Render
void Render()
{
auto width = glutGet(GLUT_WINDOW_WIDTH);
auto height = glutGet(GLUT_WINDOW_HEIGHT);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
auto program = basicShader.GetProgram();
glUseProgram(program);
// variables uniformes (constantes)
g_Camera.projectionMatrix = glm::perspectiveFov(45.f, (float)width, (float)height, 0.1f, 1000.f);
// rotation orbitale de la camera
float rotY = glm::radians(g_Camera.rotation.y);
glm::vec4 position = glm::eulerAngleY(rotY) * glm::vec4(0.0f, 0.0f, 80.0f, 1.0f);
g_Camera.viewMatrix = glm::lookAt(glm::vec3(position), glm::vec3(0.f), glm::vec3(0.f, 1.f, 0.f));
// IL FAUT TRANSFERER LES MATRICES VIEW ET PROJ AU SHADER
glBindBuffer(GL_UNIFORM_BUFFER, g_Camera.UBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 2, glm::value_ptr(g_Camera.viewMatrix), GL_STREAM_DRAW);
float yaw = glm::radians(g_Cube.rotation.y);
float pitch = glm::radians(g_Cube.rotation.x);
float roll = glm::radians(g_Cube.rotation.z);
g_Cube.worldMatrix = glm::eulerAngleYXZ(yaw, pitch, roll);
auto worldLocation = glGetUniformLocation(program, "u_worldMatrix");
auto colorLocation = glGetUniformLocation(program, "u_objectColor");
glBindVertexArray(g_Cube.VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_Cube.IBO);
for (float x = -24.f; x < 24.f; x += 3.0f)
{
for (float y = -24.f; y < 24.f; y += 3.0f)
{
for (float z = -24.f; z < 24.f; z += 3.0f)
{
glUniform4f(colorLocation, (x + 24.0f) / 48.f, (y + 24.0f) / 48.f, (z + 24.0f) / 48.f, 1.0f);
//glm::mat4 transform = glm::translate(g_Cube.worldMatrix, glm::vec3(x, y, z));
glm::mat4& transform = g_Cube.worldMatrix;
transform[3] = glm::vec4(x, y, z, 1.0f);
glUniformMatrix4fv(worldLocation, 1, GL_FALSE, glm::value_ptr(transform));
glDrawElements(GL_TRIANGLES, g_Cube.ElementCount, GL_UNSIGNED_INT, 0);
}
}
}
glBindVertexArray(0);
glutSwapBuffers();
}
示例7: Initialize
void Initialize(int width, int height)
{
printf("Version Pilote OpenGL : %s\n", glGetString(GL_VERSION));
printf("Type de GPU : %s\n", glGetString(GL_RENDERER));
printf("Fabricant : %s\n", glGetString(GL_VENDOR));
printf("Version GLSL : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
int numExtensions;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
GLenum error = glewInit();
if (error != GL_NO_ERROR) {
// TODO
}
for (int index = 0; index < numExtensions; ++index)
{
printf("Extension[%d] : %s\n", index, glGetStringi(GL_EXTENSIONS, index));
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
//glFrontFace(GL_CW);
basicShader.LoadVertexShader("basic.vs");
basicShader.LoadFragmentShader("basic.fs");
basicShader.Create();
textureShader.LoadVertexShader("texture.vs");
textureShader.LoadFragmentShader("texture.fs");
textureShader.Create();
glGenBuffers(1, &cubeVBO);
glGenBuffers(1, &cubeIBO);
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 8 * 3, g_cubeVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cubeIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * 6 * 2 * 3, g_cubeIndices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
previousTime = glutGet(GLUT_ELAPSED_TIME);
glGenVertexArrays(1, &cubeVAO);
glBindVertexArray(cubeVAO);
GLuint program = basicShader.GetProgram();
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
GLint positionLocation = glGetAttribLocation(program, "a_position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, 0);
glBindVertexArray(0);
CreateFBO(width, height);
}
示例8: Render
void Render()
{
glBindFramebuffer(GL_FRAMEBUFFER, sceneFBO);
glViewport(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
glClearColor(1.f, 0.0f, 0.5f, 1.0f);
glClearDepth(1.F);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLuint program = basicShader.GetProgram();
glUseProgram(program);
DrawCube(program);
glUseProgram(0);
#if COPY_FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, sceneFBO);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0.f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
program = textureShader.GetProgram();
glUseProgram(program);
//glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, textureObj);
//GLint textureLocation = glGetUniformLocation(program, "u_texture");
//glUniform1i(textureLocation, 0);
DrawCube(program);
#endif
glutSwapBuffers();
glutPostRedisplay();
}
示例9: Setup
bool Setup()
{
shader.LoadVertexShader("quad3d.vert");
shader.LoadFragmentShader("basic.frag");
shader.Create();
shaderSkybox.LoadVertexShader("quad3d_texture.vert");
shaderSkybox.LoadFragmentShader("basic_texture.frag");
shaderSkybox.Create();
camera.position = vec3(0.f, 300.f, -150.f); //vec3(3.f, 10.f, 20.f);vec3(0.0f, 3.f, 4.f); (3.f, 10.f, 70.f); (3.f, 20.f, 100.f)
camera.orientation = vec3(0.f, 1.f, 0.f);
camera.target = vec3(0.f, 0.f, 1.f);
mousePosition = vec3(WINDOW_WIDTH / 2.0f, WINDOW_HEIGHT / 2.0f, 0.0f);
generateGround();
EsgiTexture * texturesSkybox[] = { esgiReadTGAFile("img/skybox_left.tga"), esgiReadTGAFile("img/skybox_front.tga"), esgiReadTGAFile("img/skybox_right.tga"),
esgiReadTGAFile("img/skybox_back.tga"), esgiReadTGAFile("img/skybox_top.tga"), esgiReadTGAFile("img/skybox_bottom.tga") };
for (int i = 0; i < 6; ++i)
{
EsgiTexture * texture = texturesSkybox[i];
glGenTextures(1, &skyboxTextureIds[i]);
glBindTexture(GL_TEXTURE_2D, skyboxTextureIds[i]);
glTexImage2D(GL_TEXTURE_2D, 0, texture->internalFormat, texture->width, texture->height, 0, texture->format, texture->datatype, texture->texels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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_MAX_ANISOTROPY_EXT, 16 );
delete[] texture->texels;
delete texture;
}
EsgiTexture * texturesGround[] = { esgiReadTGAFile("img/sand.tga"), esgiReadTGAFile("img/sandhole.tga") };
for (int i = 0; i < 2; ++i)
{
EsgiTexture * texture = texturesGround[i];
glGenTextures(1, &groundTextureIds[i]);
glBindTexture(GL_TEXTURE_2D, groundTextureIds[i]);
glTexImage2D(GL_TEXTURE_2D, 0, texture->internalFormat, texture->width, texture->height, 0, texture->format, texture->datatype, texture->texels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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_MAX_ANISOTROPY_EXT, 16 );
delete[] texture->texels;
delete texture;
}
objectManager.setGravity(9.8f);
return true;
}
示例10: Render
void Render() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// alternativement on peut utiliser la nouvelle fonction glClearBufferxx()
auto basicProgram = g_BasicShader.GetProgram();
glUseProgram(basicProgram);
glBindBuffer(GL_ARRAY_BUFFER, g_Object.VBO);
g_Object.worldMatrix = glm::mat4(1.0f);
g_Camera.projectionMatrix = glm::perspectiveFov(45.f, (float) glutGet(GLUT_WINDOW_WIDTH), (float) glutGet(GLUT_WINDOW_HEIGHT), 0.1f, 1000.f);
glm::vec4 position = glm::vec4(0.0f, 0.0f, -5.0f, 1.0f);
g_Camera.viewMatrix = glm::lookAt(glm::vec3(position), glm::vec3(0.f), glm::vec3(0.f, 1.f, 0.f));
auto projLocation = glGetUniformLocation(basicProgram, "u_projectionMatrix");
glUniformMatrix4fv(projLocation, 1, GL_FALSE, glm::value_ptr(g_Camera.projectionMatrix));
auto viewLocation = glGetUniformLocation(basicProgram, "u_viewMatrix");
glUniformMatrix4fv(viewLocation, 1, GL_FALSE, glm::value_ptr(g_Camera.viewMatrix));
auto worldLocation = glGetUniformLocation(basicProgram, "u_worldMatrix");
glUniformMatrix4fv(worldLocation, 1, GL_FALSE, glm::value_ptr(g_Object.worldMatrix));
GLint colorLocation = glGetUniformLocation(basicProgram, "u_color");
GLint offsetLocation = glGetUniformLocation(basicProgram, "u_offset");
// zero correspond ici a la valeur de layout(location=0) dans le shader basic.vs
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
glEnableVertexAttribArray(0);
//rand() % 10 - 4.5
for(int i = 0; i < 10; ++i) {
glUniform3f(offsetLocation, i - 4.5, 0.0f, 0.0f);
glUniform4f(colorLocation, 0.0f, 0.0f, (float) i / 10, 0.0f);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
glutSwapBuffers();
}
示例11: Clean
void Clean()
{
shader.Destroy();
shaderSkybox.Destroy();
}
示例12: Draw
void Draw()
{
glClearColor(1.f, 1.f, 1.f, 1.f);
glClearDepth(1.f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
mat4 cameraMatrix = esgiLookAt(camera.position, camera.position + camera.target, vec3(0.0, 1.0, 0.0));
mat4 projectionMatrix = esgiPerspective(45, (float)((float)WINDOW_WIDTH/(float)WINDOW_HEIGHT), 0.01f, 10000.f);
mat4 viewMatrix = esgiMultiplyMatrix(cameraMatrix, esgiRotateY(camera.orientation.y));
mat4 modelviewMatrix;
mat4 worldMatrix;
modelviewMatrix.Identity();
worldMatrix.Identity();
modelviewMatrix = esgiMultiplyMatrix(viewMatrix, worldMatrix);
esgiUtilsDrawAxes(modelviewMatrix,projectionMatrix,1.f);
GLuint programObject = shader.GetProgram();
glUseProgram(programObject);
GLint position_attrib = glGetAttribLocation(programObject,"a_Position");
GLint color_uniform = glGetUniformLocation(programObject, "u_Color");
GLint texture_uniform = glGetUniformLocation(programObject, "u_UseTexture");
GLint depthHall_uniform = glGetUniformLocation(programObject, "u_DepthHole");
glUniform1f(depthHall_uniform, depthExplosion);
GLint viewUniform = glGetUniformLocation(programObject, "u_ViewMatrix");
glUniformMatrix4fv(viewUniform, 1, 0, &viewMatrix.I.x);
mat4 uniformMatrix = esgiRotateX(0);
GLint rotationUniform = glGetUniformLocation(programObject, "u_RotationMatrix");
glUniformMatrix4fv(rotationUniform, 1, 0, &uniformMatrix.I.x);
GLint projectionUniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
glUniformMatrix4fv(projectionUniform, 1, 0, &projectionMatrix.I.x);
worldMatrix.Identity();
worldMatrix.T.set(0.f, 0.f, 0.f, 1.f); // Translate sur l'axe z
GLint worldUnifrom = glGetUniformLocation(programObject, "u_WorldMatrix");
glUniformMatrix4fv(worldUnifrom, 1, 0, &worldMatrix.I.x);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, groundTextureIds[0]);
GLint textureUnit0 = glGetUniformLocation(programObject, "u_Texture1");
glUniform1i(textureUnit0, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, groundTextureIds[1]);
GLint textureUnit1 = glGetUniformLocation(programObject, "u_Texture2");
glUniform1i(textureUnit1, 1);
glEnableVertexAttribArray(position_attrib);
objectManager.render(&position_attrib, &color_uniform, &texture_uniform);
glDisableVertexAttribArray(position_attrib);
//---------------= SKYBOX =--------------//
programObject = shaderSkybox.GetProgram();
glUseProgram(programObject);
position_attrib = glGetAttribLocation(programObject,"a_Position");
color_uniform = glGetUniformLocation(programObject, "u_Color");
glUniform4f(color_uniform,0.f, 0.f, 0.f, 1.f);
viewUniform = glGetUniformLocation(programObject, "u_ViewMatrix");
glUniformMatrix4fv(viewUniform, 1, 0, &viewMatrix.I.x);
rotationUniform = glGetUniformLocation(programObject, "u_RotationMatrix");
glUniformMatrix4fv(rotationUniform, 1, 0, &uniformMatrix.I.x);
GLuint uniformScale = glGetUniformLocation(programObject, "u_Scale");
glUniform1f(uniformScale, scale);
GLuint uniformFace = glGetUniformLocation(programObject, "u_Face");
projectionUniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
glUniformMatrix4fv(projectionUniform, 1, 0, &projectionMatrix.I.x);
worldMatrix.Identity();
worldMatrix.T.set(0.f, 0.f, 0.f, 1.f); // Translate sur l'axe z
worldUnifrom = glGetUniformLocation(programObject, "u_WorldMatrix");
glUniformMatrix4fv(worldUnifrom, 1, 0, &worldMatrix.I.x);
for(int i = 0; i < 6; ++i)
{
glVertexAttribPointer(position_attrib, 3, GL_FLOAT, false, 0, &skybox[i].getListOfVertices()->at(0).x);
//.........这里部分代码省略.........
示例13: Render
void Render()
{
if (!g_CanDraw)
return;
auto width = glutGet(GLUT_WINDOW_WIDTH);
auto height = glutGet(GLUT_WINDOW_HEIGHT);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// variables uniformes (constantes)
g_Camera.projectionMatrix = glm::perspectiveFov(45.f, (float)width, (float)height, 0.1f, 1000.f);
// rotation orbitale de la camera
float rotY = glm::radians(g_Camera.rotation.y);
const glm::vec4 orbitDistance(0.0f, 0.0f, 200.0f, 1.0f);
glm::vec4 position = /*glm::eulerAngleY(rotY) **/ orbitDistance;
g_Camera.viewMatrix = glm::lookAt(glm::vec3(position), glm::vec3(0.f), glm::vec3(0.f, 1.f, 0.f));
glBindBuffer(GL_UNIFORM_BUFFER, g_Camera.UBO);
//glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 2, glm::value_ptr(g_Camera.viewMatrix), GL_STREAM_DRAW);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4) * 2, glm::value_ptr(g_Camera.viewMatrix));
for (uint32_t index = 0; index < g_Spheres.size(); ++index)
{
static const float radius = 100.0f;
// L'illumination s'effectue dans le repere de la camera, il faut donc que les positions des lumieres
// soient egalement exprimees dans le meme repere (view space)
g_PointLights[index].position = g_Camera.viewMatrix * glm::vec4(g_Spheres[index].position, 1.0f);
g_PointLights[index].position.w = radius;
}
glBindBuffer(GL_UNIFORM_BUFFER, PointLight::UBO);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(PointLight) * g_NumPointLights, g_PointLights);
// rendu des murs avec illumination
glBindVertexArray(g_WallMesh.VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
auto program = g_BlinnPhongShader.GetProgram();
glUseProgram(program);
auto numLightsLocation = glGetUniformLocation(program, "u_numLights");
glUniform1i(numLightsLocation, g_NumPointLights);
auto worldLocation = glGetUniformLocation(program, "u_worldMatrix");
glm::mat4& transform = g_Walls.worldMatrix;
glUniformMatrix4fv(worldLocation, 1, GL_FALSE, glm::value_ptr(transform));
auto startIndex = 0;
glBindTexture(GL_TEXTURE_2D, g_Walls.textures[Walls::gWallTexture]);
glDrawArrays(GL_TRIANGLES, startIndex, 6 * 4); startIndex += 6 * 4; // 4 murs
glBindTexture(GL_TEXTURE_2D, g_Walls.textures[Walls::gCeilingTexture]);
glDrawArrays(GL_TRIANGLES, startIndex, 6); startIndex += 6; // plafond
glBindTexture(GL_TEXTURE_2D, g_Walls.textures[Walls::gFloorTexture]);
glDrawArrays(GL_TRIANGLES, startIndex, 6); startIndex += 6; // sol
// rendu debug
glBindTexture(GL_TEXTURE_2D, 0);
glBindVertexArray(g_SphereMesh.VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_SphereMesh.IBO);
program = g_AmbientShader.GetProgram();
glUseProgram(program);
worldLocation = glGetUniformLocation(program, "u_worldMatrix");
for (auto index = 0; index < g_Spheres.size(); ++index)
{
glm::mat4& transform = g_Spheres[index].worldMatrix;
glUniformMatrix4fv(worldLocation, 1, GL_FALSE, glm::value_ptr(transform));
glDrawElements(GL_TRIANGLES, g_SphereMesh.ElementCount, GL_UNSIGNED_INT, 0);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
//glBindVertexArray(0);
// dessine les tweakBar
TwDraw();
glutSwapBuffers();
}
示例14: Initialize
void Initialize()
{
printf("Version Pilote OpenGL : %s\n", glGetString(GL_VERSION));
printf("Type de GPU : %s\n", glGetString(GL_RENDERER));
printf("Fabricant : %s\n", glGetString(GL_VENDOR));
printf("Version GLSL : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
int numExtensions;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
GLenum error = glewInit();
if (error != GL_NO_ERROR) {
// TODO
}
#if LIST_EXTENSIONS
for (int index = 0; index < numExtensions; ++index)
{
printf("Extension[%d] : %s\n", index, glGetStringi(GL_EXTENSIONS, index));
}
#endif
#ifdef _WIN32
// on coupe la synchro vertical pour voir l'effet du delta time
wglSwapIntervalEXT(0);
#endif
// render states par defaut
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
// AntTweakBar
TwInit(TW_OPENGL, NULL); // ou TW_OPENGL_CORE selon le cas de figure
objTweakBar = TwNewBar("Multiple Point Lights");
TwAddVarRW(objTweakBar, "Num Point Lights", TW_TYPE_UINT32, &g_NumPointLights, "");
TwAddButton(objTweakBar, "Quitter", &ExitCallbackTw, nullptr, "");
// Objets OpenGL
glGenBuffers(1, &g_Camera.UBO);
glBindBuffer(GL_UNIFORM_BUFFER, g_Camera.UBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 2, nullptr, GL_STREAM_DRAW);
glGenBuffers(1, &PointLight::UBO);
glBindBuffer(GL_UNIFORM_BUFFER, PointLight::UBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(PointLight) * MAX_POINT_LIGHTS, nullptr, GL_STREAM_DRAW);
glGenBuffers(1, &Material::UBO);
glBindBuffer(GL_UNIFORM_BUFFER, Material::UBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(Material), &g_ShinyMaterial, GL_STATIC_DRAW);
error = glGetError(); assert(error == GL_NO_ERROR);
g_AmbientShader.LoadVertexShader("ambient.vs");
g_AmbientShader.LoadFragmentShader("ambient.fs");
g_AmbientShader.Create();
auto program = g_AmbientShader.GetProgram();
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_Camera.UBO);
auto blockIndex = glGetUniformBlockIndex(program, "ViewProj");
glUniformBlockBinding(program, blockIndex, 0);
error = glGetError(); assert(error == GL_NO_ERROR);
g_BlinnPhongShader.LoadVertexShader("blinnPhong.vs");
g_BlinnPhongShader.LoadFragmentShader("blinnPhong.fs");
g_BlinnPhongShader.Create();
program = g_BlinnPhongShader.GetProgram();
//glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_Camera.UBO); // deja bound
blockIndex = glGetUniformBlockIndex(program, "ViewProj");
glUniformBlockBinding(program, blockIndex, 0);
glBindBufferBase(GL_UNIFORM_BUFFER, 1, PointLight::UBO);
blockIndex = glGetUniformBlockIndex(program, "Lights");
glUniformBlockBinding(program, blockIndex, 1);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, Material::UBO);
blockIndex = glGetUniformBlockIndex(program, "Material");
glUniformBlockBinding(program, blockIndex, 2);
// Setup
error = glGetError(); assert(error == GL_NO_ERROR);
previousTime = glutGet(GLUT_ELAPSED_TIME);
LoadMesh(g_WallMesh, g_Room);
LoadAndCreateTextureRGBA("wall_color_map.jpg", g_Walls.textures[Walls::gWallTexture]);
glBindTexture(GL_TEXTURE_2D, g_Walls.textures[Walls::gWallTexture]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
LoadAndCreateTextureRGBA("floor_color_map.jpg", g_Walls.textures[Walls::gFloorTexture]);
glBindTexture(GL_TEXTURE_2D, g_Walls.textures[Walls::gFloorTexture]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
LoadAndCreateTextureRGBA("ceiling_color_map.jpg", g_Walls.textures[Walls::gCeilingTexture]);
//.........这里部分代码省略.........
示例15: Terminate
void Terminate() {
g_BasicShader.Destroy();
glDeleteBuffers(1, &g_Object.VBO);
}