views:

406

answers:

2

Hi, I'm working on an OpenGL project in which I want to draw a star. It doesn't necessarily have to be a 3d looking star (2d looking is fine). I have the xyz coordinates for the center of the star and I know the size I'd like it to be. I don't do much OpenGL/3d math programming, so any help here would be much appreciated.

EDIT: More detail: I'm not sure if this is possible but can I draw a 2D looking star at some point in 3d space? I tried simple with a square and tried something like:

gl.glTranslated(x, y, z);
gl.glBegin(GL.GL_QUADS);
gl.glVertex2D(x-size,y-size);
gl.glVertex2D(x-size,y+size);
gl.glVertex2D(x+size,y+size);
gl.glVertex2D(x+size,y-size);
gl.glEnd();

The square did not seem to be at the correct depth even though I translated to the x,y,z. It appeared to be closer to the front of the screen than it should be. Is it possible to translate a 2d shape in 3d like this?

thanks,

Jeff

+1  A: 

Did you set up your projection matrix? If not, it is probably set to identity, which means the z values of your vertices will have no effect on their rendered positions in screen space. To get the sense of depth you want, you need to create a perspective projection matrix. You can use glFrustum() to create your projection matrix. Here's an example (from Wikipedia's OpenGL page):

glMatrixMode( GL_PROJECTION );      /* Subsequent matrix commands will affect the projection matrix */
glLoadIdentity();                   /* Initialise the projection matrix to identity */
glFrustum( -1, 1, -1, 1, 1, 1000 ); /* Apply a perspective-projection matrix */

There are a ton of free OpenGL tutorials online, so you shouldn't have any trouble finding more info.

Donnie DeBoer
Interesting. (FYI I'm working inside the NASA WorldWind application). However, if I do something like gluSphere(...) the sphere does draw in the correct place. I'll readup more on the matrices, thanks!
Jeff Storey
A: 

I decided to go with the 3d drawing and it looks like the translation was actually already done for me and I didn't need to retranslate. So in fact I was translating away from the point. Thanks for everyone's help.

Jeff Storey