Jump to content

  • Log In with Google      Sign In   
  • Create Account

problem with 3d renderingb


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 thejelmega   Members   -  Reputation: 122

Like
0Likes
Like

Posted 21 April 2014 - 02:33 PM

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, 21 April 2014 - 02:34 PM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS