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.