0

I am using VAOs and Mapped VBOs together to get as much performance as I can. Now, my VBOs are interleaved in this form VCVCVCVCVCVC so there is vertex of 3 floats then a color of 4 floats.

My problem is that it doesn't recognize the color even when I have the correct stride and offset. This problem started happening when I implemented VAOs.

Imported parts of the code: Mapping the VBO and creating the VAO

Binding everything:

glBindVertexArray(vaoHandel);

glBindBuffer(GL_ARRAY_BUFFER, vboHandel);
glBufferData(GL_ARRAY_BUFFER, NumberOfIndecies << 2, GL_STATIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, false, 7<<2, 0<<2);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 7<<2, 3<<2);
glEnableVertexAttribArray(1);

Mapping part:

ByteBuffer dataBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY, NumberofIndecies << 2, null);
FloatBuffer vboData = dataBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer();

Bulding the VBO:

build(vboData);
vboData.flip();

Unmapping:

glUnmapBuffer(GL_ARRAY_BUFFER);

Unbinding:

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

That was building and mapping the VBO and VAO. Rendering:

glBindVertexArray(vaoHandel);

glDrawArrays(GL_QUADS, 0,  capacity);                   

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glBindVertexArray(0);

So again to recap My problem is that the COLORS don't work, they don't show up. The QUADS that I am drawing show up but they are WHITE. When after checking the colors I'm putting in are clearly RED.

Amit Assaraf
  • 512
  • 11
  • 34
  • `vboData.flip()` What does that do? Also, what are you *doing* with the colors? Colors are only "colors" because your shader uses them as colors. Is your shader using them as colors? Also, what does this mysterious `build` function do? – Nicol Bolas Jun 08 '13 at 22:36
  • 1
    `7<<2` If your Java compiler cannot internally turn `7 * 4` into that, then you need a new Java compiler. It's always best to write things in the most obvious way possible, and `7<<2` isn't it. – Nicol Bolas Jun 08 '13 at 22:37
  • @NicolBolas Believe it or not, but for some people 7<<2 makes more sense. Try coding in some assembler language for a while, see if you still think it's an odd way of writing things. It makes absolutely no difference for functionality, so there is no reason to use either way over the other. It's just a matter of preference. – Kevin Jun 08 '13 at 23:37
  • Why do you call `glEnableVertexAttribArray` and `glDisableVertexAttribArray` in your draw code? – Grimmy Jun 09 '13 at 00:18
  • What shader? I dont use shaders and the build function fills up the buffer with the vertices. Fixed the enableVAO thing – Amit Assaraf Jun 09 '13 at 06:30
  • You still call `glDisableVertexAttribArray` in your draw code. The state is encapsulated in the VAO, so if you start disabling stuff later on you might screw up your data binding. – Grimmy Jun 10 '13 at 06:48
  • The next issue is.. what does the index parameter in `glVertexAttribPointer` actually mean when you are not using shaders? Are you calling `glEnableClientState` using `GL_COLOR_ARRAY` and `GL_VERTEX_ARRAY` at some point? You pretty much have to do what when using fixed pipeline, but I have no idea if the VAO encapsulate it. – Grimmy Jun 10 '13 at 07:01
  • I am calling glEnableState.. and According the the LWJGL tutorials its possible to use VAOs without shaders.. What am I doing wrong? I am doing exactly what is specified in this tutorial: http://lwjgl.org/wiki/index.php?title=The_Quad_with_DrawArrays The only thing that I am doing different is that I am using interleaved VBOs but thats it.. – Amit Assaraf Jun 10 '13 at 11:21
  • 1
    Look at the last answer : http://stackoverflow.com/questions/12237652/how-does-opengl-know-what-type-each-vertex-buffer-object-is – Grimmy Jun 11 '13 at 13:00
  • Thanks. I decided to just not use VAOs and whats weird is that in the tutorial that I linked they are not using shaders and I am guessing its because of the fact they are not using anything but vertices so they dont need shaders.. – Amit Assaraf Jun 11 '13 at 20:50
  • 1
    Might be the case, or the person was just lucky that his version of drivers managed to correctly render his geometry even though a lot of the things done creates undefined behavior. Also, why not start using shaders? :) – Grimmy Jun 12 '13 at 01:43
  • I do not understand how they work.. Why are they better and how are they different than other methods of rendering.. – Amit Assaraf Jun 12 '13 at 11:24
  • By using shaders you leave behind several metric tons of cruft and states that has accumulated in the OpenGL API over the years. Shaders give you the ability to transform your data in any way you want, and you have full control over final fragment you are writing. You mainly have to care about shaders, textures, vaos and fbos to achieve your goals. It's simple and powerful. If you know the basics about projection/modelview/normal matrices you should not have much to worry about. – Grimmy Jun 14 '13 at 02:31

0 Answers0