Sign in to follow this  
CK08

OpenGL How to draw a 3D object?

Recommended Posts

Hi, I'm a OpenGL beginner. I would like to crete a 3D sofa object to put in 3D world. And I think of assemble 4 cubic rectangles to form the sofa by specifying every vertex and connect them together. Who knows a faster way? I was trying to draw a rectangle using QUAD and array, but somehow it desn't work... Here's a portion of my code: static GLfloat frontPoly [24] = { {-43.5, 28.5, 88.75}, {-43.5, 28.5, 70.25}, {43.5, 28.5, 70.25}, {43.5, 28.5, 88.75}, {43.5, -28.5, 88.75}, {-43.5, -28.5, 88.75}, {-43.5, -28.5, 70.2}, {43.5, -28.5, 70.25} }; void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0f, 1.0f, 1.0f); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, frontPoly); glRotatef(90.0, 1.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glArrayElement(0); glArrayElement(1); glArrayElement(2); glArrayElement(3); glEnd(); glFlush(); } ... Can anyone tells me what's wrong with the codes? [Edited by - CK08 on March 5, 2008 3:18:00 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by CK08
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1.0f, 1.0f, 1.0f);

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, frontPoly);

glRotatef(90.0, 1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glArrayElement(0);
glArrayElement(1);
glArrayElement(2);
glArrayElement(3);
glEnd();

glFlush();
}



This is going to be slow because you are making a snot load of calls to opengl each of which has to be processed by the cpu before being turned over to the gpu for additional work. Graphics programming is something to large to describe in a forum post I would suggest getting two books one on graphics theory, and one on opengl.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this