Mesh::Mesh()
{
... //some initializations
m_pVertices[0].x = 0.0f;
m_pVertices[0].y = 0.0f;
m_pVertices[0].z = -2.0f;
m_pTexCoords[0].u = 0.0f;
m_pTexCoords[0].v = 0.0f;
m_pVertices[1].x = 2.0f;
m_pVertices[1].y = 0.0f;
m_pVertices[1].z = -2.0f;
m_pTexCoords[1].u = 1.0f;
m_pTexCoords[1].v = 0.0f;
m_pVertices[2].x = 2.0f;
m_pVertices[2].y = 2.0f;
m_pVertices[2].z = -2.0f;
m_pTexCoords[2].u = 1.0f;
m_pTexCoords[2].v = 1.0f;
}
void Mesh::BuildVBOs()
{
glGenBuffersARB( 1, &m_nVBOVertices );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pVertices, GL_STATIC_DRAW_ARB );
glGenBuffersARB( 1, &m_nVBOTexCoords );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*2*sizeof(float), m_pTexCoords, GL_STATIC_DRAW_ARB );
}
void Mesh::draw()
{
if (isSet == false)
{
BuildVBOs();
isSet = true;
}
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
glBindTexture(GL_TEXTURE_2D, getTexture("data/pictures/grass1.png"));
glDrawArrays( GL_TRIANGLES, 0, m_nVertexCount );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
VBOs drawn incorrectly
Looks fine, you may have to watch out for padding of your structure.
If you have
struct Myvertex
{
};
use sizeof(Myvertex)
If you have
struct Myvertex
{
};
use sizeof(Myvertex)
thx, but always the same problem
I use classes, not structs, but thats not important ;)
What I can't understand, is, how Opengl knows, what are the x, y and z coordinates. Do I have to tell it that?
I only can think, that's the problem...
PS: Thx, you solved the problem ;) I used struct instead of a Class now and it works perfectly. Perhaps i can fix it to work with classes too
I use classes, not structs, but thats not important ;)
What I can't understand, is, how Opengl knows, what are the x, y and z coordinates. Do I have to tell it that?
I only can think, that's the problem...
PS: Thx, you solved the problem ;) I used struct instead of a Class now and it works perfectly. Perhaps i can fix it to work with classes too
This call
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
should be
glVertexPointer( 3, GL_FLOAT, sizeof(Myvertex), (char *) NULL );
whether you use struct or class.
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
should be
glVertexPointer( 3, GL_FLOAT, sizeof(Myvertex), (char *) NULL );
whether you use struct or class.
hey
You also don't seem to unbind your VBO's after use, which I think could cause such problems. You can unbind your Vertex Buffer alike... glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);.
cyas
You also don't seem to unbind your VBO's after use, which I think could cause such problems. You can unbind your Vertex Buffer alike... glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);.
cyas
one thing to be aware of when yo use classes, if there are any virtual functions, then thre is a hidden v-table pointer, thus:
then sizeof(tickle) will be 8 bytes on 32-bit (and probably 16 or 12 bytes on 64bit).
Not to mention, you do not know where the v-table pointer is packed within the class tickleme.
where as
class tickleme{public: int x; tickleme(void); virtual ~tickleme();};
then sizeof(tickle) will be 8 bytes on 32-bit (and probably 16 or 12 bytes on 64bit).
Not to mention, you do not know where the v-table pointer is packed within the class tickleme.
where as
class tickleme_again{public: int x; tickleme_again(void);};will have size equal to sizeof(int).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement