Jump to content
  • Advertisement
Sign in to follow this  
CK08

OpenGL How to draw a 3D object?

This topic is 3853 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

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
Advertisement
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
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!