1 Replies - 525 Views - Last Post: 23 October 2013 - 09:13 PM Rate Topic: -----

#1 xnewix  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 204
  • Joined: 23-May 09

Opengl VBO with c++ not displaying triangles

Posted 22 October 2013 - 02:34 PM

I not getting any visable output from my VBO code. Im trying to switch from glBegin()..etc to VBO to draw scene of triangles using a set of points and indices..

I'm not sure what arguments i should be passing into glBufferData and glBufferSubData. What I wanted was to send the x,y,z values of each point to the buffer, but i can't see a way to do that.

Points containes the vertices in no particular order
Triangles referances which three vertices to use to make a triangle



GLuint Point3dBufferId;
	GLuint IndexBufferId;

	glGenBuffersARB(1,&Point3dBufferId);
	glBindBufferARB(GL_ARRAY_BUFFER, Point3dBufferId);
	glBufferDataARB(GL_ARRAY_BUFFER, sphere.point3d.size() * sizeof(Point3d), NULL, GL_DYNAMIC_DRAW);
	glBufferSubDataARB(GL_ARRAY_BUFFER,0,sphere.point3d.size() * (3*sizeof(float)),&sphere.point3d[0]);
   	
	glGenBuffersARB(1,&IndexBufferId);
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);
	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, sphere.triangle3d.size() * sizeof(Triangle3d), NULL, GL_STATIC_DRAW);
	glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER,0,sphere.triangle3d.size() * (3*sizeof(float)),&sphere.triangle3d[0]);

	// render
	glBindBufferARB(GL_ARRAY_BUFFER, Point3dBufferId);
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);

	glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3,GL_FLOAT,0,NULL);
		glDrawElements(GL_TRIANGLES, sphere.triangle3d.size(), GL_INT, NULL);
	glDisableClientState(GL_VERTEX_ARRAY);


Classes for points and triangles

class Point3d {
private:
	float v[3];
public:
	Point3d(float nx,float ny,float nz) { 
		v[0]=nx;
		v[1]=ny;
		v[2]=nz;	
	}
	Point3d()   {}
	~Point3d()  {}

	float getx() { return v[0]; }
	float gety() { return v[1]; }
	float getz() { return v[2]; }

};    

class Triangle3d {
private:
	int v[3];	
public:
	Triangle3d(int nv1, int nv2, int nv3) { 
		v[0]=nv1;
		v[1]=nv2;
		v[2]=nv3;
	}
	Triangle3d()  {}
	~Triangle3d() {}
	
	int getv1() { return v[0]; }
	int getv2() { return v[1]; }
	int getv3() { return v[2]; }
};


Is This A Good Question/Topic? 0
  • +

Replies To: Opengl VBO with c++ not displaying triangles

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: Opengl VBO with c++ not displaying triangles

Posted 23 October 2013 - 09:13 PM

Hi, would a triangle not have three points?

In the glBufferSubDataARB() function, offset appear to be in bytes.

glBufferData and glBufferSubData
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1