Register
handmade.network»Forums»Please help... Trying to learn OpenGL
14 posts
Please help... Trying to learn OpenGL
3 months, 2 weeks ago Edited by BernFeth on June 7, 2020, 11:35 p.m. Reason: Initial post
Hey guys.

So I've been reading OpenGL superbible and trying to learn it.

I managed to get things working until the vbo part, I've been messing around with it but can't get anything but a blank screen...

I have the following texture, position and indices arrays:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
static r32 TextureData[] =
{
  0, 1,
  1, 1,
  1, 0,
  0, 0,
};

static r32 Size = 200.0f;
static r32 HalfSize = Size/2;
static r32 PositionData[] =
{
  -HalfSize, -HalfSize, 0,
   HalfSize, -HalfSize, 0,
   HalfSize,  HalfSize, 0,
  -HalfSize,  HalfSize, 0,
};

static GLubyte Indices[] =
{
  0, 1, 2,
  0, 2, 3,
};

static GLuint Vbos[3];


Then inside my InitScene function which is called once at the start of the game:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
glFrontFace(GL_CCW);
glCullFace(GL_BACK);

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glGenBuffers(3, Vbos);

glBindBuffer(GL_ARRAY_BUFFER, Vbos[0]);
glBufferData(GL_ARRAY_BUFFER, 4*3*sizeof(GLfloat),
  PositionData, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, Vbos[1]);
glBufferData(GL_ARRAY_BUFFER, 4*2*sizeof(GLfloat),
  TextureData, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Vbos[2]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*sizeof(GLubyte),
  Indices, GL_STATIC_DRAW);


Finally, my DrawScene function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
  glTranslatef(WindowInfo.Width/2, WindowInfo.Height/2, -10);

  glBindTexture(GL_TEXTURE_2D, Textures[0]);

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

  glBindBuffer(GL_ARRAY_BUFFER, Vbos[1]);
  glTexCoordPointer(2, GL_FLOAT, 0, 0);

  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Vbos[2]);
  glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0);

glPopMatrix();


The textures are loaded once at the start as well, I know they are working properly since I had it working with vertex arrays just before I changed the code to use vertex buffers.

Am I making a silly mistake somewhere?

Thanks.
14 posts
Please help... Trying to learn OpenGL
3 months, 2 weeks ago
Oh... Turns out I still had to call glEnableClientState(GL_VERTEX_ARRAY) before glVertexPointer() and glEnableClientState(GL_TEXTURE_COORD_ARRAY) before glTexCoordPointer()...

Sorry guys, it was a silly mistake after all...