PDA

View Full Version : Nothing Renders to the Screen



Rosenzweig
08-07-2012, 09:02 AM
In my code, nothing renders to the screen. Everything is fine and glError() doesn't show anything, yet nothing will render to the dang screen. I think it might be a scope issue (glDrawElements might not be getting the index info), but I'm not sure. I passed this around to a few buddies and they can't make heads or tails about it, so would anyone mind just pointing out the big dummy mistake that I made? Thanks!

https://github.com/Rosenzweig/RosenGL/tree/master/rosengl

V-man
08-07-2012, 02:00 PM
I didn't look at the entire code but just perusing the code, I noticed that player.cpp
has an array with 4 vertices and the color array has only a single RGB. You need to have 4 RGB otherwise your PC will blow a fuse.

Also your call to glDrawElements is wrong

glDrawElements(GL_TRIANGLES, sizeof(player_indices), GL_UNSIGNED_INT, 0);You need to give the number of indices, which is 4 in your case.

Besides that, which GL are you using?
If it is GL 3.2 core, then you must use VAO as well.

Rosenzweig
08-07-2012, 05:09 PM
I didn't look at the entire code but just perusing the code, I noticed that player.cpp
has an array with 4 vertices and the color array has only a single RGB. You need to have 4 RGB otherwise your PC will blow a fuse.

Also your call to glDrawElements is wrong

glDrawElements(GL_TRIANGLES, sizeof(player_indices), GL_UNSIGNED_INT, 0);You need to give the number of indices, which is 4 in your case.

Besides that, which GL are you using?
If it is GL 3.2 core, then you must use VAO as well.

First of all, thanks for your answer. The glDrawElements function I misunderstand. Okay, so it's not the amount of indices you're using, but the amount of elements I'm drawing? Is it not two then? I'm kind of confused on this. As for the colors I should have 4 colors because 4 vertices? How come it wastes resources with only one RGB? As for the VAO suggestion, I haven't specified which version of OpenGL to use in my code but I have a GTX 480 and it does use OpenGL 4.2, but I don't think it's needed. This is actually a port of some code I did a long while back and it followed this same system and it rendered correctly.

Thanks though, I'm walking one more step closer to becoming a good GL programmer.

V-man
08-08-2012, 03:26 AM
It is the amount indices.
Since you want to draw 2 triangles, how many indices is that?

You are only drawing a couple of triangles and you are worried about wasting memory?

If you have created the context the old fashion way, then you aren't forced to used VAO.

Rosenzweig
08-08-2012, 06:13 AM
Then is it not 6? 3 for each Triangle? As for wasting memory, didn't you bring that up? I didn't know just laying down one RGB for the whole rectangle would blow a fuse. Every tutorial I've followed never mentions that. As for my context, I just use GLEW.

Edit:
Oh you meant because the color would only be bound to one side of the rectangle. Never mind.

Rosenzweig
08-08-2012, 08:08 AM
Guess what the problem was? I forgot one comma in my player_vertices array. Nothing and nobody could detect it, but that was it. I'm surprised there wasn't a compiler error.

V-man
08-08-2012, 02:57 PM
Then is it not 6? 3 for each Triangle?
Yes, that is correct.



As for wasting memory, didn't you bring that up? I didn't know just laying down one RGB for the whole rectangle would blow a fuse. Every tutorial I've followed never mentions that.
Then those aren't good tutorials.
If you are going to send vertices and color, then each vertex must have a color associated with it.
Or, if you will be submitting vertices and normals and colors, then again, each vertex must have a normal and color.
....and so on.
This is explained in the Wiki FAQ
http://www.opengl.org/wiki/FAQ#Multi_indexed_rendering



As for my context, I just use GLEW.
GLEW doesn't create a context.
http://www.opengl.org/wiki/OpenGL_Loading_Library



Edit:
Oh you meant because the color would only be bound to one side of the rectangle. Never mind.
You have only provided 1 color, which would be for the first vertex. The other 3 vertices don't have a color and you risk crashing your system.