English 中文(简体)
Java OpenGL draw a star
原标题:

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

最佳回答

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.

问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签