Skip to main content
GameDev.net gamedev.net
🔒 Locked

Buffer?

Started by sjoerd222 Dec 28, 2006 at 4:23 AM 0 replies 600+ views
Original Post
sjoerd222
sjoerd222
Hi It seems that I am not able to buffer the data problaby. When I render the stuff, on one computer it works fine, on an other i does not. My one-> GF7, the other an elder radon with new driver. But on both computer occurs that the image gets weird when I change the buffered data. The way I buffered it should be useful nad fast If I do nto change the values very often, and so I do. If I'm worng, please tell me, thx. Please have a look at the following code: (Using VBO's) Here I Buffer the stuff:

WORLD.buildworld(0,30);
	PolBuffer.resize(countpsector(&WORLD.mainarea.sector[0][0]));
	TexBuffer.resize(countpsector(&WORLD.mainarea.sector[0][0])*2/3);
	loadSector(&WORLD.mainarea.sector[0][0],&PolBuffer, &TexBuffer,0,0);


	

	glGenBuffers(1, &polbufferID);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, polbufferID);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB,
countpsector(&WORLD.mainarea.sector[0][0])*sizeof(GLfloat),
PolBuffer.getData(), GL_STATIC_DRAW_ARB);
	glVertexPointer( 3, GL_FLOAT, 0, bufferObjectPtr(0) );

	//Load Bitmap
	SDL_Surface *bmpFile;
	bmpFile= SDL_LoadBMP("map/textures/nehe.bmp");
 
	
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
 		
	glGenTextures(1,&texture);
	glBindTexture(GL_TEXTURE_2D,texture);
 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexImage2D( GL_TEXTURE_2D, 0, 3, bmpFile->w, bmpFile->h, 0, 
GL_BGR, GL_UNSIGNED_BYTE, bmpFile->pixels );
	
	
	glGenBuffersARB( 1, &texbufferID );                 // Get A Valid Name
	glBindBufferARB( GL_ARRAY_BUFFER_ARB, texbufferID);
	glBufferDataARB( GL_ARRAY_BUFFER_ARB,
countpsector(&WORLD.mainarea.sector[0][0])*2/3*sizeof(GLfloat),
TexBuffer.getData(), GL_STATIC_DRAW_ARB);
	glTexCoordPointer(2, GL_FLOAT, 0, bufferObjectPtr(0) );
	
	drawstartIDX = 0;
	drawendIDX = (GLuint)countpsector(&WORLD.mainarea.sector[0][0]);

	SDL_FreeSurface( bmpFile );





I call PolBuffer.getData(), this is a function of my glVecBuffer class:

//----------------------------------------------------------
class glVec{
	public:
	GLfloat x;
	GLfloat y;
	GLfloat z;
};
//----------------------------------------------------------
class glVecBuffer{
	private:
	GLfloat *data;
	GLint size;
	GLint idx;
	public:
	glVecBuffer(GLint);
	glVecBuffer(){

	};
	~glVecBuffer(){
		delete[] data;
	};
	GLfloat& operator[](int index)
	{
		if (index<0||index > size){
			return(data[0]);	
		}
		return(data[index]);
	};
	int getSize();
	void resize(GLint);
	void push(GLfloat);
	void startpush(GLint);
	GLfloat* getData();
};
glVecBuffer::glVecBuffer(GLint newsize){
	size=newsize;
	data = new GLfloat[size];
	for(int i;i<newsize;i++){
		data = 0.f;
	}
};
void glVecBuffer::resize(GLint newsize){
	GLfloat *newdata = new GLfloat[newsize];
	if (newsize<size){
		size = newsize;
	}
	for (int i=0;i<size;i++){
		newdata = data;
	}
	delete[] data;
	size = newsize;
	data = newdata;
};
GLfloat* glVecBuffer::getData(){
	return(data);
}
int glVecBuffer::getSize(){
	return(size);
}
void glVecBuffer::push(GLfloat value){
	if (idx<size){
		data[idx++] = value;
	}
};
void glVecBuffer::startpush(GLint NewIdx){
	idx = NewIdx;
};





That's the way I render:

glEnable( GL_TEXTURE_2D );
	
	glEnableClientState( GL_VERTEX_ARRAY );	
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );

	glBindBufferARB( GL_ARRAY_BUFFER_ARB, polbufferID);
	glVertexPointer( 3, GL_FLOAT, 0, bufferObjectPtr(0));

	glBindBuffer( GL_ARRAY_BUFFER_ARB, texbufferID);
	glTexCoordPointer(2, GL_FLOAT, 0, bufferObjectPtr(0));


	glDrawArrays( GL_TRIANGLES, drawstartIDX,drawendIDX);

	glDisableClientState( GL_VERTEX_ARRAY );
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );





And, here the Code that should once change the height:(only showing the part that changes the buffer)

glBindBufferARB(GL_ARRAY_BUFFER_ARB, polbufferID);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB);

		//glBindBufferARB( GL_ARRAY_BUFFER_ARB, texbufferID);
		//glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB);

		//drawstartIDX = 0;
		//drawendIDX = 0;

		glBindBufferARB(GL_ARRAY_BUFFER_ARB, polbufferID);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB,
countpsector(&WORLD.mainarea.sector[0][0])*sizeof(GLfloat), PolBuffer.getData(), GL_STATIC_DRAW_ARB);
		glVertexPointer( 3, GL_FLOAT, 0, bufferObjectPtr(0) );

		//glBindBufferARB( GL_ARRAY_BUFFER_ARB, texbufferID);
		//glBufferDataARB( GL_ARRAY_BUFFER_ARB, countpsector(&WORLD.mainarea.sector[0][0])*2/3*sizeof(GLfloat), TexBuffer.getData(), GL_STATIC_DRAW_ARB);
		//glTexCoordPointer(2, GL_FLOAT, 0, bufferObjectPtr(0));






Thank you
May the force be with... me! :-D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.