HELP!!!! My final project is an OpenGL program!!!

This is my first time posting here. I’m a computer science student in my last semester of college. My professor has assigned us a program to do in OpenGL (which will be compiled in Visual C++. What we are to do is render a drawing of a bug. I know how to render its body, but how am I going to attach the legs and eyes if I don’t know what vertices I’m dealing with? In my Graphics textbook and all OpenGL sample code I’ve seen, the vertices are small numbers like 1.0, -1.0, etc. My professor will NOT teach us. She expects us to teach ourselves, and I find that very unfair and very unprofessional. If you guys can give me some pointers, I’d appreciate it so much!

Tara

not sure by what you mean… can you clarify your question?

Are you asking about the range??
What data type those verticies are??

Clarification on the question would be nice… or I am just dumb and don’t understand… one or the other

To better explain my problem, I’ll first present a sample program that draws a 3D cube:

/*

  • cube.c
  • Draws a 3-D cube, viewed with perspective, stretched
  • along the y-axis.
    */
    #include “glos.h”

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>

void myinit(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
void CALLBACK display(void);

/* Clear the screen. Set the current color to white.

  • Draw the wire frame cube.
    /
    void CALLBACK display (void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f (1.0, 1.0, 1.0);
    glLoadIdentity (); /
    clear the matrix /
    glTranslatef (0.0, 0.0, -5.0); /
    viewing transformation /
    glScalef (1.0, 2.0, 1.0); /
    modeling transformation /
    auxWireCube(1.0); /
    draw the cube */
    glFlush();
    }

void myinit (void) {
glShadeModel (GL_FLAT);
}

/* Called when the window is first opened and whenever

  • the window is reconfigured (moved or resized).
    /
    void CALLBACK myReshape(GLsizei w, GLsizei h)
    {
    glMatrixMode (GL_PROJECTION); /
    prepare for and then /
    glLoadIdentity (); /
    define the projection /
    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); /
    transformation /
    glMatrixMode (GL_MODELVIEW); /
    back to modelview matrix /
    glViewport (0, 0, w, h); /
    define the viewport */
    }

/* Main Loop

  • Open window with initial window size, title bar,
  • RGBA display mode, and handle input events.
    /
    int main(int argc, char
    * argv)
    {
    auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
    auxInitPosition (0, 0, 500, 500);
    auxInitWindow (“Perspective 3-D Cube”);
    myinit ();
    auxReshapeFunc (myReshape);
    auxMainLoop(display);
    return(0);
    }

My assignment is to do pretty much the same thing except we have to draw a bug instead of a cube. I can certainly use this program as a skeleton and the cube as the bug’s body, but my question is, how am I gonna attach the legs and the eyes without knowing the coordinates of those vertices? BTW, this is my first time writing an OpenGL program. I am extremely new to this language. Anyway, I hope this clears things up.

Tara

You can do a lot of things here. Basically, all the work you need to do is in the display() function. This is where you will draw your bug.

The key thing to remember about the aux* drawing function is that they draw shapes which are centered at the origin. For instance, the wire cube with side-length 1.0 (as in the example code you posted) will be a cube centered at the point (0, 0, 0) and length of each side 1.0. This means that the 8 vertices of the cube will be:
(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)

Your main work will be done in the display() function. In there, you will draw your bug’s arms and legs. I might suggest that you have separate functions like:
DrawBody(), DrawLeg(), DrawArm(), DrawAntenae()

Then you would do something like:
glMatrixMode(GL_MODELVIEW);
// Translate to the position of the body
DrawBody();

// Translate to the position of the left arm
DrawArm();

// Translate to the position of the right arm
DrawArm();

// Do the same for the legs

Now, how you translate is up to you. You can use push and pop matrix operations on the modelview matrix in order to translate to the position of the arms relative to the body or, alternatively, relative to the world origin. My advice would be to do the translation of the arms/legs/antennae relative to the body of the bug. This way, if you move the body, then the rest of the bug’s parts move with it and you don’t have to calculate new positions for each thing attached to the body.

One last thing, the thing you have to remember about drawing objects using the aux drawing functions (like auxWireCube) is that they draw things so that the center of the object is at 0,0,0 (in local coordinates). In other words, if you have the modelview matrix as the identity and issue a AuxWireCube(1.0) call, then the resulting cube has vertices:
(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)
(-0.5, -0.5, 0.5)
(-0.5, 0.5, 0.5)

(0.5, 0.5, -0.5)
(0.5, -0.5, -0.5)
(-0.5, -0.5, -0.5)
(-0.5, 0.5, -0.5)

You really need to think of things in “relative” positions rather than absolute positions.

I hope this helps. Good luck on your project.

Sorry about the double replies above. The first one is a partial reply. I messed up and hit the submit button before I was done.

Thank you Ben! I’ll give that I try, and if I have any more questions, I’ll give you a holler.