# OpenGL OGL is not rendering my mesh

## Recommended Posts

Hi! I'm working on this 3d-engine which is supposed to support both OpenGL and Direct3D. Up until yesterday, i've been storing all my vertex-data in RAM, so I decided to convert it to upload all the data to the graphics-card. I know my data is correct, since it worked when I stored it the regular way (using a vertex-array, and an index-array). This is the old code: loading:
void VertexBuffer::Create(int p_iSize,void *p_pxData)
{
m_iSize=p_iSize;
m_pxBuffer=new Vertex[m_iSize];
memcpy(m_pxBuffer,p_pxData,m_iSize*sizeof(Vertex));
};

void IndexBuffer::Create(int p_iSize,void *p_pxData)
{
m_iSize=p_iSize;
m_piBuffer = new u16[m_iSize];
memcpy(m_piBuffer,p_pxData,m_iSize*sizeof(u16));
};

rendering:
Model *pxModel=p_pxRenderNode->GetModel();
Mesh *pxMesh=pxModel->Submesh(0);

Texture *pxTexture=p_pxRenderNode->GetTexture();
SetTexture(pxTexture,0);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,sizeof(Vertex),((float*)pxMesh->GetVB()->GetData())+6); // GetData( ) returns a vertex-array. Note that the vertex from this version looked different
glVertexPointer(3,GL_FLOAT,sizeof(Vertex),pxMesh->GetVB()->GetData());
glDrawElements(GL_TRIANGLES,pxMesh->GetIB()->Size(),GL_UNSIGNED_SHORT,pxMesh->GetIB()->GetData());

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

void GLVertexBuffer::create( int p_iSize, Vertex *p_pxData )
{
#define BUFFER_OFFSET( i ) ( (char *)NULL + ( i ) )

m_iSize = p_iSize;

glGenBuffers( 1, &m_iVBId );					// Get A Valid Name
glBindBuffer( GL_ARRAY_BUFFER, m_iVBId );// Bind The Buffer
glBufferData( GL_ARRAY_BUFFER, p_iSize*sizeof(Vertex), NULL, GL_STATIC_DRAW );
glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(Vertex) * p_iSize, p_pxData );

glTexCoordPointer( 2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 24 ) );
glNormalPointer( GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 12 ) );
glVertexPointer( 3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 0 ) );

// Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
delete [] p_pxData; p_pxData = NULL;
};

bool GLIndexBuffer::create( int p_iSize, u16 *p_pxData ){
m_iSize = p_iSize;

glGenBuffers( 1, &m_iIBId );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_iIBId );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, p_iSize * sizeof( u16 ), p_pxData, GL_STATIC_DRAW );

return true;
};


rendering:
#define BUFFER_OFFSET( i ) ((char *)NULL + (i))

Model *pxModel = p_pxRenderNode->GetModel( );
GLMesh *pxMesh = static_cast<GLMesh*>( pxModel->Submesh( 0 ) );
GLIndexBuffer* pxI = static_cast<GLIndexBuffer*>( pxMesh->getIB( ) );
GLVertexBuffer* pxV = static_cast<GLVertexBuffer*>( pxMesh->getVB( ) );

Texture *pxTexture = p_pxRenderNode->GetTexture( );
SetTexture( pxTexture, 0 );

glBindBuffer(GL_ARRAY_BUFFER, pxV->getId( ) );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pxI->getID( ) );

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glTexCoordPointer( 2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 24 ) );
glNormalPointer( GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 12 ) );
glVertexPointer( 3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET( 0 ) );		// Set The Vertex Pointer To The Vertex Buffer

glDrawElements( GL_TRIANGLES, pxI->size( ), GL_UNSIGNED_BYTE, BUFFER_OFFSET( 0 ) );

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

Am i doing something obviously wrong? I am new to VBOs, since I've only been using Direct3D before, so i wouldn't be surprised. =P Thanks. // Christo EDIT: Maybe it helps to see the vertex-class old:
class Vertex
{
public:
float vx,vy,vz;
float nx,ny,nz;
float tu0,tv0;
};

new:
class Vertex
{
public:
bool operator == ( const Vertex& p_xOther ){
return(
pos[0] == p_xOther.pos[0] &&
pos[1] == p_xOther.pos[1] &&
pos[2] == p_xOther.pos[2] &&
normal[0] == p_xOther.normal[0] &&
normal[1] == p_xOther.normal[1] &&
normal[2] == p_xOther.normal[2] &&
uv[0] == p_xOther.uv[0] &&
uv[1] == p_xOther.uv[1]
);
};

float pos[3];
float normal[3];
float uv[2];
};

There...nothing weird, but there you have it.

##### Share on other sites
I don't see anything wrong here but there are some unneeded and things:

1. Remove glVertexPointer, glNormalPointer, glTexCoordPointer from VBO::create

2. Why you are using glBufferSubData when you can add the vertices here from glBufferData itself?

to the question:
Have you tried using GL_UNSIGNED_INT to see if it works? And are you sure you are loading vertices and indices correctly to the buffer?

btw. its not necessary to change float x,y,z; to float pos[3]; (same for normal and texcoord)

[Edited by - Kasya on February 24, 2010 2:00:12 PM]

##### Share on other sites
I've tried both GL_UNSIGNED_INT, GL_UNSIGNED_SHORT and GL_UNSIGNED_BYTE.
And yes, i am pretty sure. It worked on the old code, and i haven't changed a single line of code in the loading of the mesh.
I've tried setting a break-point in the create-functions, and p_pxData seems to be correct (although I can't swear, since we're talking ~27000 indices and ~8000 vertices), and anyway I can't think of a reason why it would be changed, since it is the same as before.

##### Share on other sites
Thanks a lot! I removed the glVertexPointer, glNormalPointer, glTextCoordPointer from GLVertexBuffer::create, and now it shows just fine!
Thanks for the help :)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978705
• ### Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12