Advertisement

Stupid Vertex Buffer Question

Started by April 06, 2001 08:09 AM
5 comments, last by Punika 23 years, 3 months ago
Hi, at the moment I want to figure out how to use the Vertex Buffer with glDrawElements. My problem is that this code don`t draw anything but I don`t know why. What`s wrong with it ?

glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
uint uiIndices[3]={0,1,2};
float vertex[12]={-1.0f,1.0f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f};
glVertexPointer( 3, GL_FLOAT, 0, vertex );
glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, uiIndices );
  
Thanks for your help Lutz Hören Punika [EDITED:] GL_VERTEX_ARRAY is enabled ! [ Power Productions ] Edited by - Punika on April 6, 2001 9:10:57 AM
Punika
It seems that you have an array size of 12, when it''s only supposed to hold 9.

try changing:

float vertex[12]={-1.0f,1.0f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f};

to:

float vertex[9]={-1.0f,1.0f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f};
Advertisement
Yes, but that`s not the problem. I changed it to 12 when I have tried a quad. At the moment I am changing it to 9. But the same result. No, drawing

Punika

Learning by doing
Punika
Well, i dont use the draw elements function, though in delphi, i do something like this:

glVertexPointer(3,GL_FLOAT,0,@VERTEX_ARRAY);
glDrawArrays(GL_POLYGON,0,PointCount);

where @VERTEX_ARRAY is a pointer to my VERTEX_ARRAY[9]
quote:
Original post by Punika

Yes, but that`s not the problem. I changed it to 12 when I have tried a quad. At the moment I am changing it to 9. But the same result. No, drawing

Punika

Learning by doing

hmm, your code works fine for me


glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (0.0f, 0.0f, -6.0f);

glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
unsigned int uiIndices[3]={0,1,2};
float vertex[9]={-1.0f,-1.0f,0.0f, -1.0f,1.0f,0.0f, 1.0f,1.0f,0.0f};
glVertexPointer( 3, GL_FLOAT, 0, vertex );
//glIndexPointer( GL_UNSIGNED_INT,0,uiIndices
glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, uiIndices );


glFlush ();

It really works but why is this stupid triangle black ?

Punika

Learning by doing
Punika
Advertisement
are lights enabled? is color material enabled? is the camera looking at the front of the faces?

Edited by - a2k on November 13, 2001 7:27:56 PM
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement