Jump to content
  • Advertisement
Sign in to follow this  
javisam376

OpenGL Help with basics

This topic is 3492 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 need to draw a table with a few spheres over it on opengl with c++... the main idea is to draw a table of dimensions 2.4x1.3 and take a look from above.... the balls have a radius of 0.08 (using the same system as the table)... I have been looking around for code but it is very confusing because there are a lot of options... can somebody help me with the basics of this??? I mean, i know i need a main method which should look includes call to glutInitDisplayMode, glutDisplayFunc, glutMainLoop and a display(void) method to be called by glutDisplayFunc().... I guess what i need help the most is in translating the coordinates to the correct system and then setting the view point... any help will be welcome...

Share this post


Link to post
Share on other sites
Advertisement
Are you confused about what? How to code C++? The OpenGL part?

Check out the NeHe tutorials they are great for learning. I am fairly new to this myself.
http://nehe.gamedev.net/ - nehe tutorials.

A table could be constructed with Quads, and balls(spheres) can be constructed with Glut.

To set up the perspective your going to want to use, gluLookAt, and set the Y Coordinate above the table height and set yLookAt variable downward.

Are you attempting to make a pool/billiards game or something?

Share this post


Link to post
Share on other sites
I get how to draw the table with glquads and how to draw balls as solid shperes...

What i need help with is with translating the coordinates (the size of the table has to be 2.4x1.2 because there are some calculations that needs those values) and to set up the camera to have a look to the upper part of the table with the balls....

Share this post


Link to post
Share on other sites
Okay so when you're making the table with quad's just scale the vertices so that way it matches your desired size.
ex:
gl.glVertex3f(X, Y , Z);

It can be hard setting up everything to the exact dimensions that you want but it is far from impossible.

Like I said, use the gluLookAt to set up where the 'camera'/'observer' is and where it is facing.(This should be in your Display function)
ex:
glu.gluLookAt(CameraX, CameraY, CameraZ, LookAtX, LookAtY, LookAtZ, 0, 1,0);

So once you 'draw' your table you set the CameraY to be taller than the table and you set your LookAt_ Variables to be aiming towards the table's location.

I'm not gonna write the code for drawing your table specifically, for a few reasons. A) I don't use C++. B) You have to learn it :).

Share this post


Link to post
Share on other sites
THanks for your answer...

I got it done to a point, i am getting closer but there is still something missing...

i am calling gl_quad with the desired values (1.3 and 2.4, for example one vertix is glVertex3f(0.0f ,0.0f, 1.30f)) and then trying to play with gluLookAt like this gluLookAt(30, 20, 30, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ) but i can't get the whole thing to fit into the screen... the corner missing is the one corresponding to the coordinates (2.4, 0, 1.3)....

I am also calling glOrtho with the following parameters: ( -1, 1, -1, 1, 1, 256 ); and I was playing wit the first 3 elements of glulookat but i can get close to 175 for the x and z axis and if i go beyond those numbers the entire quad is missing...

any help??

Share this post


Link to post
Share on other sites
Oh! that is probably due to your:

glu.gluPerspective(FOV, width/height, NearClipping, FarClipping);

Try increasing your FarClipping variable. That variable is how many units into depth you can see.

Share this post


Link to post
Share on other sites
Thanks... I solved the problem by using glortho... i belive I have come a long way since my initial post yesterday.... thanks for the help guys...

however, now i am having a different problem: when i first draw the scene everything looks like i want it to look... but when I select another window and that window is over the current animation window, the objects in the animation look "darker" when iget back to the animation window... I tried adding glutpostredisplay inside the method called by glutIdleFunc, but then the animation shows the right colors only for the first frame and then they become "darker"....

in the main metho i call:
...
glutDisplayFunc( display );
glutIdleFunc
...

in display i call:
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
gluOrtho2D( 0, width, 0, height );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// draw objects
// show light

glutSwapBuffers( );

In glutidlefun i call glutPostRedisplay and i will call the method that estimates the movement based on the time...

any help???

Javier...

Share this post


Link to post
Share on other sites
Wow, I wish I knew I've never had that happen. and Your welcome for whatever help I may have provided. :) it's good to see that your making lot's of progress however!

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!