i'm trying to get into OpenGL with C++ but sometimes it just knocks me out
I was searching also some time but could not find any help, maybe i just did not find the right thing.
So:
I've first tried to get something on the screen with vbos in general, so i made a vbo for vertices, colors and texcoords. Worked, i had my textured quad( made of tri-strips ).
Then i tried to put all the data into one vbo.
I wrote a vertex struct, reserved space for 4 of them in the vbo and then went on as before.
I passed the size of the vertex struct as stride and the offset inside the struct for each gl*Pointer call.
The problem i got is simple: There is nothing to see, no quad, no colors, no texture, just the blank background.
I hope i give you enough information, if not just tell me what you need.
Thanks to everyone.
So, see the codes yourself:
First try with 3 vbos:
GLfloat vertices[] = { 200.f, 228.f, 0.f,
200.f, 100.f, 0.f,
456.f, 228.f, 0.f,
456.f, 100.f, 0.f };
GLubyte colors[] = { 255, 255, 255,
255, 255, 255,
255, 255, 255,
255, 255, 255 };
GLfloat texCoords[] = { 0.f, 1.f,
0.f, 0.f,
1.f, 1.f,
1.f, 0.f };
GLuint vertId = -1;
GLuint colId = -1;
GLuint texId = -1;
glGenBuffers( 1, &vertId );
glGenBuffers( 1, &colId );
glGenBuffers( 1, &texId );
// Vertices
glBindBuffer( GL_ARRAY_BUFFER, vertId );
glBufferData( GL_ARRAY_BUFFER, 4 * 3 * sizeof( GLfloat ), vertices, GL_STATIC_DRAW );
// Colors
glBindBuffer( GL_ARRAY_BUFFER, colId );
glBufferData( GL_ARRAY_BUFFER, 4 * 3 * sizeof( GLubyte ), colors, GL_STATIC_DRAW );
// Texture
glBindBuffer( GL_ARRAY_BUFFER, texId );
glBufferData( GL_ARRAY_BUFFER, 4 * 2 * sizeof( GLfloat ), texCoords, GL_STATIC_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glEnable( GL_TEXTURE_2D );
// Drawing in render call
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, vertId );
glVertexPointer( 3, GL_FLOAT, 0, 0 );
glBindBuffer( GL_ARRAY_BUFFER, colId );
glColorPointer( 3, GL_UNSIGNED_BYTE, 0, 0 );
glBindBuffer( GL_ARRAY_BUFFER, texId );
glTexCoordPointer( 2, GL_FLOAT, 0, 0 );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
Second try with vertex struct and one vbo:
#define BUFFER_OFFSET(i) ((char *)NULL + (i)) // taken from the opengl wiki
typedef struct _DSE_Vertex
{
float x,y,z;
float r,g,b,a;
float u,v;
} Vertex;
Vertex quad[4];
// setVertexValues( Vertex& vert, x, y, z, r, g, b, a, u, v ) // all float
setVertexValues( quad[0], 200.f, 228.f, 1.f, 1.f, 1.f, 1.f, 1.f,
0.f, 1.f );
setVertexValues( quad[1], 200.f, 100.f, 1.f, 1.f, 1.f, 1.f, 1.f,
0.f, 0.f );
setVertexValues( quad[2], 456.f, 228.f, 1.f, 1.f, 1.f, 1.f, 1.f,
1.f, 1.f );
setVertexValues( quad[3], 456.f, 100.f, 1.f, 1.f, 1.f, 1.f, 1.f,
1.f, 0.f );
GLuint vbo = -1;
glGenBuffers( 1, &vbo );
glBindBuffer( GL_ARRAY_BUFFER, vbo );
glBufferData( GL_ARRAY_BUFFER, sizeof( Vertex ) * 4, quad, GL_STATIC_DRAW );
uint stride = sizeof( Vertex ); // It's 36 bytes
glEnable( GL_TEXTURE_2D );
// Drawing in render call
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, vbo );
glVertexPointer( 3, GL_FLOAT, stride, 0 );
glColorPointer( 4, GL_FLOAT, stride, BUFFER_OFFSET( 12 ) );
glTexCoordPointer( 2, GL_FLOAT, stride, BUFFER_OFFSET( 28 ) );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );