Jump to content
  • Advertisement
Sign in to follow this  
Calsmurf2904

OpenGL Some issues

This topic is 3622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, Its a long time since my last post here. I am creating a Game in the Ogre engine and when I am on the pc that is too slow to program with Ogre then I am learning OpenGL. This is my issue : I have two classes called PXVertex and PXVertexBuffer. PXVertexBuffer has a std::Vector that contains PXVertex objects. The main problem is that when I am trying to draw the buffer is keeps giving me Access Violation at 0x00000000. This is my current Code : Adding vertex to buffer
	void PXVertexBuffer::addVertex(PXVector mVec)
	{
	        if((mVertexes.size() + 1) > mVertexes.capacity())
		{
			totalVertexes++;
			mVertexes.resize(totalVertexes);
		}
		mVertexes.push_back(new PXVertex(mVec.getX(),mVec.getY(),mVec.getZ(),mVec.getColor()));
	};
Retrieving vertex from buffer
	PXVertex* PXVertexBuffer::getVertex(int id)
	{
		return mVertexes.at(id);
	};
Drawing Vertexes
		bool _Update()
		{
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
			glLoadIdentity();
			glTranslatef(-1.5f,0.0f,-6.0f);
			int i = 1;
			int i2 = 1;
			VVertexBuffer::iterator mIt = mBuffers.begin();
			while(mIt != mBuffers.end())
			{
				glBegin(GL_TRIANGLES);
				VVertex::iterator mIt2 = mBuffers.at(i)->getBeginIterator();
				i2 = 0;
				for(mIt2 = mBuffers.at(i)->getBeginIterator();mIt2 != mBuffers.at(i)->getEndIterator();++mIt2)
				{
					float x,y,z;
					PXVertex* mVertex = *mIt2;
					x = mVertex->getX();
					y = mVertex->getY();
					z = mVertex->getZ();
					glVertex3f(x,y,z);
					mIt2++;
				        i2++;
				};
				glEnd();
				mIt++;
				i++;
			};
			if(!_UpdateRenderWindows()) return false;
			return true;
		};
The buffers are placed in a vector of PXVertexBuffer objects. The vector variable is named mBuffers. The problem is in mVertex->getX()/Y/Z; One more thing : How can I color the vertex ? I thought glColor4f(r,g,b,a); but I am not sure.

Share this post


Link to post
Share on other sites
Advertisement
Maybe you should start at index 0 instead of 1, or even better: replace the calls mBuffers.at(i) and use your iterator (mIt). For your vertexcolor: Yes, glColor(xn) is a possibility.

Share this post


Link to post
Share on other sites
still getting it :(
This is my current code :

VVertexBuffer::iterator mIt = mBuffers.begin();
for(mIt = mBuffers.begin();mIt != mBuffers.end();++mIt)
{
glBegin(GL_TRIANGLES);
VVertex::iterator mIt2 = (*mIt)->getBeginIterator();
for(mIt2 = (*mIt)->getBeginIterator();mIt2 != (*mIt)->getEndIterator();++mIt2)
{
float x,y,z,r,g,b,a;
PXVertex* mVertex = *mIt2;
x = mVertex->getX();
y = mVertex->getY();
z = mVertex->getZ();
r = mVertex->getColor().getR();
g = mVertex->getColor().getG();
b = mVertex->getColor().getB();
a = mVertex->getColor().getA();
glColor4f(r,g,b,a);
glVertex3f(x,y,z);
};
glEnd();
};

I am starting to think that the error is in the addVertex code.

Edit:
Okay....I am looking into some other more optimized methods for rendering.
I am thinking about using VBO's to draw the vertexes.
However would it be possible to copy the vector as a array to the vbo ?
Here:
http://www.ozone3d.net/tutorials/opengl_vbo_p2.php
they use a simple array of static GLFloat's.
Would it be use instead of a array of GLFloat's a vector ?

Edit2:
Created a test code :

int vertexes = 0;
VVertexBuffer::iterator mIt = mBuffers.begin();
for(mIt = mBuffers.begin();mIt != mBuffers.end();++mIt)
{
glBindBuffer(GL_ARRAY_BUFFER,(*mIt)->VBOVertexId);
glBufferData(GL_ARRAY_BUFFER,(*mIt)->getTotalVertexes()*sizeof((*mIt)->getVertexArray()),(*mIt)->getVertexArray(),GL_DYNAMIC_DRAW);
glVertexPointer(3,GL_FLOAT,sizeof(PXVertex),0);

glBindBuffer(GL_ARRAY_BUFFER,(*mIt)->VBOColorId);
glBufferData(GL_ARRAY_BUFFER,(*mIt)->getTotalVertexes()*sizeof((*mIt)->createColorArray()),(*mIt)->createColorArray(),GL_DYNAMIC_DRAW);
glColorPointer(4,GL_FLOAT,sizeof(PXColor),0);
vertexes += (*mIt)->getTotalVertexes();
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLES,0,vertexes);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

Here are the problems with this code :
It keeps complaining that GL_ARRAY_BUFFER and GL_DYNAMIC_DRAW is undefined.
It also keeps saying that glBindBuffer and glBufferData doesn't exist.
What am I doing wrong ?
I am using Visual C++ 2008 sp1 on Windows (Kinda obvious).

Edit3:
Okay....added glew 1.5.1 and the errors are now gone (well....new errors appeared lol).
Trying to fix them now....will post here later with the result.

[Edited by - Calsmurf2904 on November 21, 2008 11:28:25 AM]

Share this post


Link to post
Share on other sites
Okay fixed the issues...I can now succesfully compile it :)
However there is a new access violation.
The access violation this time is in this code :

totalBuffers++;
mBuffers.resize(totalBuffers);
mBuffers.push_back(mVertexBuffer);
GLuint BufferIds2[1] = {0};
glGenBuffers(1,BufferIds2); //VertexBuffer <-------- There
BufferIds[totalBuffersId+1] = BufferIds2[0];
glGenBuffers(1,BufferIds2); //ColorBuffer
BufferIds[totalBuffersId+2] = BufferIds2[0];
totalBuffersId++;
totalBuffersId++;

This code is to add the vertex buffer to the vector.
I thought then I need to generate the VBO's here.
So when I try to generate them it gives me :
Quote:

Access violation reading location 0x00000000

Share this post


Link to post
Share on other sites
ok...finally got it running by disabling VBO and using Vertex Arrays instead.
However there still isn't anything drawn to the screen.
This is my initialisation code :
Quote:

PXMesh* mMesh = mRoot->createMesh("ProjectXTestMesh.PX");
mMesh->getVertexBuffer()->addVertex(PXVector4(0.0f,1.0f,0.0f,PXColor(100,100,100,1))); mMesh->getVertexBuffer()->addVertex(PXVector4(-1.0f,-1.0f,0.0f,PXColor(100,100,100,1)));
mMesh->getVertexBuffer()->addVertex(PXVector4(1.0f,-1.0f,0.0f,PXColor(100,100,100,1)));

and then the code to draw it :
Quote:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
VVertexBuffer::iterator mIt = mBuffers.begin();
int Vertexes = 0;
for(mIt = mBuffers.begin();mIt != mBuffers.end();++mIt)
{
glVertexPointer(3,GL_FLOAT,sizeof(PXVertex),&(*mIt)->getVertexArray());
glColorPointer(3,GL_FLOAT,sizeof(PXVertex),&(*mIt)->getVertexArray().at(0).r);
Vertexes += (*mIt)->getTotalVertexes();
};
glDrawArrays(GL_TRIANGLES,0,Vertexes);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!