PDA

View Full Version : Bug



Magnificence
04-12-2011, 02:02 PM
I really don't know what I'm doing wrong, it seems like it used the work, I don't know what should be wrong about this code. Can anyone help me with that? I shouldn't be to much code.

This first piece of code is called before any other code I will show you.

glEnable( GL_DEPTH_TEST );
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

const GLfloat vertices[] = {
2.0f, -1.333333f, 0.25f,
-2.0f, -1.333333f, 0.25f,
0.0f, 2.666667f, 0.25f,

2.0f, 1.333333f, -0.25f,
-2.0f, 1.333333f, -0.25f,
0.0f, -2.666667f, -0.25f
};

const GLuint colors[] = {
64, 64, 128,
64, 64, 128,
64, 64, 255,

255, 255, 0,
255, 255, 0,
128, 128, 0
};

glGenBuffers( 2, _buffer_handles );

glBindBuffer( GL_ARRAY_BUFFER, _buffer_handles[0] );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat) * 18, vertices, GL_STATIC_DRAW );

glBindBuffer( GL_ARRAY_BUFFER, _buffer_handles[1] );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLubyte ) * 18, colors, GL_STATIC_DRAW );

Then, when the window resizes and just after the previous code, the following code will be excecuted:

glViewport( 0, 0, new_width, new_height );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

set_perspective_3d( scene.view.field_of_view, (GLfloat)new_width / (GLfloat)new_height, scene.view.near_clip, scene.view.far_clip );

glMatrixMode( GL_MODELVIEW );
The "set_perspective_3d" function is basically the same as "gluPerspective".

Then, somewhere everytime a new frame has to be rendered, the following code will render the new frame:


glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 10.0f);

glBindBuffer( GL_ARRAY_BUFFER, _buffer_handles[0] );
glVertexPointer( 3, GL_FLOAT, 0, 0 );

glBindBuffer( GL_ARRAY_BUFFER, _buffer_handles[1] );
glColorPointer( 3, GL_UNSIGNED_BYTE, 0, 0 );

glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glDrawArrays( GL_TRIANGLES, 0, 6 );
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );


But all I see is a blackness, a completely black screen.

Thank you.

Magnificence
04-12-2011, 02:11 PM
Ohhh...... I see the problem, really this has been bugging me for days and just when I post the question, I figure it out xD.

Aparantly I was drawing the vertices behind the camera, I wanted them in from so I changed the translate function to move -10 at Z.

LOL

carsten neumann
04-12-2011, 02:54 PM
const GLuint colors[] = { ... };

glBufferData( GL_ARRAY_BUFFER, sizeof( GLubyte ) * 18, colors, GL_STATIC_DRAW );


also, type missmatch GLuint, sizeof(GLubyte)

mhagain
04-12-2011, 04:23 PM
glColorPointer with a 3 byte colour format may not be stable on all systems; I'm almost certain I've seen it give trouble before.