Jump to content
  • Advertisement
Sign in to follow this  
thejelmega

OpenGL problem with 3d renderingb

This topic is 1944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I've been following a tutorial: http://openglbook.com/the-book/chapter-4-entering-the-third-dimension/

to know how I start 3d rendering, but if I run it I get nothing

 

So could anyone help

 

setup code:

  buffers:

GLfloat vertices[] =
{
-0.5f, -0.5f,  0.5f, 1,   0, 0, 1, 1,
-0.5f,  0.5f,  0.5f, 1,   1, 0, 0, 1,
0.5f,  0.5f,  0.5f, 1,   0, 1, 0, 1,
0.5f, -0.5f,  0.5f, 1,   1, 1, 0, 1,
-0.5f, -0.5f, -0.5f, 1,   1, 1, 1, 1,
-0.5f,  0.5f, -0.5f, 1,   1, 0, 0, 1,
0.5f,  0.5f, -0.5f, 1,   1, 0, 1, 1,
0.5f, -0.5f, -0.5f, 1,   0, 0, 1, 1
};
 
GLuint indices[] =
{
0, 2, 1,  0, 3, 2,
4, 3, 0,  4, 7, 3,
4, 1, 5,  4, 0, 1,
3, 6, 2,  3, 7, 6,
1, 6, 5,  1, 2, 6,
7, 5, 6,  7, 4, 5
};
 
 
 
GLint vertexSize = 8 * sizeof(GLfloat); 
GLint rgbaOffset = 4 * sizeof(GLfloat);
 
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
 
glGenBuffers(1, &iboID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
 
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, vertexSize, (void*)rgbaOffset);
glBindVertexArray(0);
 
 
 
  and the other stuff, like shaders and matrices:
aspect = (GLfloat)screen_width / (GLfloat)screen_height;
 
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
 
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); //default value
 
/*glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);*/
 
projectionMat = glm::mat4(1.0f);
viewMat = glm::mat4(1.0f);
modelMat = glm::mat4(1.0f);
 
pos = glm::vec3(0.0, 0.0, -2.0);
viewMat = glm::translate(glm::mat4(), pos);
 
glViewport(0, 0, screen_width, screen_height);
projectionMat = glm::perspective(fov, aspect, zNear, zFar);
 
createVertexArray();
 
vertexShader = new Shader("matVert.glsl", GL_VERTEX_SHADER);
fragmentShader = new Shader("defaultFrag.glsl", GL_FRAGMENT_SHADER);
shaderProg = new ShaderProgram();
 
shaderProg->attachShader(vertexShader);
shaderProg->attachShader(fragmentShader);
 
shaderProg->bindAttibLocation(0, "vPosition");
shaderProg->bindAttibLocation(1, "vColor");
 
shaderProg->link();
 
MVPLoc = shaderProg->GetUniformLoc("MVP");
 
shaderProg->Use();
 
 
 
and my render code:
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
MVP = modelMat * viewMat * projectionMat;
glUniformMatrix4fv(MVPLoc, 1, GL_FALSE, glm::value_ptr(MVP));
 
glBindVertexArray(vaoID);
 
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, (GLvoid*)0);
 
glBindVertexArray(0);
Edited by thejelmega

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!