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

VertexArray Buffer

Started by sjoerd222 Jan 3, 2007 at 12:23 PM 0 replies 450+ views
Original Post
sjoerd222
sjoerd222
Hi Would anybody of you be so kind, and have a close look at my glVecBuffer class, which I buffer glBufferData(...,...,AnyglVecBuffer.getData(),...) I think there is something wrong with this class. On some Computers it works, on some it does not. It lacks in allocation the correct memory space or something simular I suspect. here you have the code:

//----------------------------------------------------------
class glVec{
	public:
	GLfloat x;
	GLfloat y;
	GLfloat z;
	glVec(){
		x = 0.f;
		y = 0.f;
		z = 0.f;
	}
};
//----------------------------------------------------------
class glVecBuffer{
	private:
	GLfloat *data;
	GLint size;
	GLint idx;
	public:
	glVecBuffer(GLint);
	glVecBuffer(){
		data = new GLfloat[1];
		data[0] = 0.f;
		size = 1;
	};
	~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=0;i<newsize;i++){
		data = 0.f;
	}
};
void glVecBuffer::resize(GLint newsize){
	int tmp;
	GLfloat *newdata = new GLfloat[newsize];
	for (int i=0;i<newsize;i++){
		newdata = 0.f;
	}
	if(newsize<size) {
		tmp=newsize;
	}
	else{
		 tmp=size;
	}
	for (int i=0;i<tmp;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;
};;


By the way. Does anybody know I can change the size of the buffered vertexarray? I thought I call glBufferData(...,...,NULL,..) and then glBufferData with the new bigger/smaller data. But this does cause errors with the image, maythis is caused by the my mystic error cannot find. And if my use of C++ is ood, please tell me what to change, wonna learn something. Thank you guys!!! Would be really great if you could help me!!!
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.