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.

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 on other sites
nehe.gamedev.net is a great place to start for OGL beginners.

Share on other sites
Quote:
 Original post by CK08void 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 on other sites
Thanks for all the suggestions.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 24
• 9
• 57
• Forum Statistics

• Total Topics
632640
• Total Posts
3007616
• Who's Online (See full list)

There are no registered users currently online

×