Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Jul 2012
Offline Last Active Private

Posts I've Made

In Topic: Only the last instance is rendered

17 September 2015 - 02:38 PM

The std130 layout will pad out the float to a vec4. The buffer won't be the right size for the uniform struct in the shader and the shader will read zero.

In Topic: OBJ File Problem

01 December 2014 - 10:46 PM

For example, let's make position 6 be 0,1,0. The faces would then be: f (0,1,0)/11 5/12 1/9  then later on f 7/15, (0,1,0)/16 ... Two faces can and do touch after all. They aren't assigned, the data is just used in that order. If any part of the full vertex (position + uv) doesn't match another full vertex they are unique even if part is the same (and get different indices for the GL element buffer). You will end up duplicating data, outputing a position multiple times if it appears with different uvs.


Also, easier to think of those v-lines as positions.

Edit: if that's not terribly clear, I apologize. I'm exhausted. I'll post some code tomorrow if necessary.

In Topic: OBJ File Problem

30 November 2014 - 11:16 AM

If you need indices for your engine (or just want to always use indexed renders) Sponji has the right info.

What I was getting at with a flat array is that you can build a flat array from the indices after you've read the file:

std::vector<int> indices; // pairs: position, uv, position, uv, etc
std::vector<vertex> vertices(indices.size()/2);
for(int i = 0; i < indices.size()/2; ++i)
vertices[i].x = points[indices[i]].x; // and y, z
vertices[i].u = texcoords[indices[i+1]].u // and v
// where points and texcoords are the v and vt from the obj file
// and indices is all of the face data. and then 'vertices' is all you need into one vbo with glDrawArrays.

In Topic: OBJ File Problem

29 November 2014 - 10:48 PM

OpenGL only supports 1 index buffer, where an index refers to the "complete" vertex that includes all attributes (uv, normal, etc).

The easiest way to go is to copy the position and uv coordinates to a buffer as you read (or after) the indices and just render using glDrawArrays without

an element array buffer. Otherwise, you'll need to build a new index buffer based on unique pairs of position+uv.


Also, the binding of GL_ELEMENT_ARRAY_BUFFER is part of the state of a vertex array. Even if you set up glVertexAttribPointers later, you might as well bind the VAO before the element buffer and have that all set (and not messing up the previous VAO's state).

In Topic: Simple Cube not Showing up with simple Example ...

27 October 2014 - 10:52 AM

The vertex shader input attributes need to be assigned a location, whether with layout or glBindAttribLocation.


MatricesUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "MatrixInformation"); glUniformBlockBinding(MainOpenGLShaderProgramID, MatricesUniformBlockID, 1);

glGenBuffers(1, &MatricesUniformBufferID);

glBindBuffer(GL_UNIFORM_BUFFER, MatricesUniformBufferID);

glBindBufferBase(GL_UNIFORM_BUFFER, 1, MatricesUniformBufferID); GLsizeiptr TotalBufferSize = sizeof(glm::mat4) + sizeof(glm::mat4); TotalBufferSize += sizeof(glm::mat3);
glBufferData(GL_ARRAY_BUFFER, TotalBufferSize, NULL, GL_DYNAMIC_DRAW);



There's a typo highlighted, that should be GL_UNIFORM_BUFFER.

Also, I didn't try to get the lighting glsl to work, I just output red from the fragment shader to make sure there was output.

It's a cube!