Show Posts
|
|
Pages: [1] 2
|
|
3
|
Java Game APIs & Engines / JOGL Development / Re: How to shade the background?
|
on: 2009-08-23 20:52:06
|
Just put a textured quad in the background that's big enough to cover it. Good idea, thanks! Thought there was any built in method for this, but the quad works perfect. Be sure to make it immune to camera changes.
That was easy made by putting the quad before initiating the camera, then it becomes immune to camera changes. 
|
|
|
|
|
7
|
Java Game APIs & Engines / JOGL Development / Re: Make a reflection of a texture
|
on: 2009-08-19 21:50:57
|
I have now succeeded in creating a quad below the main quad: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| gl.glBegin(gl.GL_QUADS); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(topLeft, 1.0f, 0.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(topRight, 1.0f, 0); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(bottomRight, -1.0f, 0); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(bottomLeft, -1.0f, 0.0f); gl.glEnd();
gl.glBegin(gl.GL_QUADS); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(topLeft, -1.0f, 0.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(topRight, -1.0f, 0); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(bottomRight, -3.0f, 0); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(bottomLeft, -3.0f, 0.0f); gl.glEnd(); |
The problem is that the image on the reflection quads is not upside-down as I want it to be. If I add 1
| gl.glRotated(180,0,0,0); |
everything is messed up since I am creating a lot of quads with binded textures in a loop. How to I rotate every "reflection quad" 180 degrees without messing up the first quads?
|
|
|
|
|
13
|
Java Game APIs & Engines / JOGL Development / Overlay object does not work properly
|
on: 2009-08-09 20:11:49
|
I am trying to put an Overlay over the openGL panel. I have this in the init() method: 1 2
| overlay = new Overlay(drawable); graphics2d = overlay.createGraphics(); |
And I have this in the display() method: 1 2 3
| overlay.drawAll(); graphics2d.setBackground(Color.yellow); graphics2d.drawString("HELLO WORLD!", 10, 10); |
Nothing but all the OpenGL stuff appears on the screen. "Hello world" is not beeing printed. What am I doing wrong?
|
|
|
|
|
15
|
Java Game APIs & Engines / JOGL Development / Re: How do I run my opengl application?
|
on: 2009-08-09 19:27:49
|
Hmm, it works if I start the application using the command line, but not if I doubble click on the jar file. How come? Sometimes the problem is because of a failed attempt to "install" jogl manually by copying the jars/dlls to some system or jre folder. If you did so, remove any occurance of jogl/gluegen jars and dlls outside of your project folder and the netbeans profile directory from your system and try again.
I will try that. Thanks!
|
|
|
|
|
17
|
Java Game APIs & Engines / JOGL Development / How do I run my opengl application?
|
on: 2009-08-09 16:50:31
|
|
I´m using NetBeans opengl pack.
I made a simple opengl application that I would like to run without using NetBeans.
In the folder C:\...\NetBeansProjects\myApp\dist-windows-amd64 there is a jar file and some dll files. myApp.jar is not possible to start, no jar file starts in the whole myApp folder. What am I doing wrong?
|
|
|
|
|
18
|
Java Game APIs & Engines / JOGL Development / "No OpenGL context current on this thread" - why?
|
on: 2009-08-09 15:56:10
|
I have a method that loads a texture called loadTexture(). The method just does this: 1
| textures = TextureIO.newTexture(new java.io.File("image.jpg"), false); |
If I call that method from an actionListener (actionPerformed method) I get this error: 1
| javax.media.opengl.GLException: No OpenGL context current on this thread |
If I call loadTexture() from the init() methot, I don´t get the exception. I want to load the texture by pressing a button, so why do I get that exception when trying to call the method from the action listener?
|
|
|
|
|
20
|
Java Game APIs & Engines / JOGL Development / Get the left-most quad appear to the right when dissappearing to the left
|
on: 2009-08-09 13:33:41
|
Hello! The method called from the display list draws some quads in a horizontal line. You can make the quads going left or right by pressing the arrow keys, then the X_POS variable is changing. When you press left or right many times, the quads will finally disappear from the view. 1 2
| gl.glTranslatef(X_POS, 0.0f, -6.0f); gl.glCallList(quad); |
I would like to make the left-most quad appear on the right side when it dissappears to the left, and the right-most quad appear to the left when it dissappears to the right, so that the quads never disappear from the view even if I press the left left key for a month.  How can I achieve this?
|
|
|
|
|
22
|
Java Game APIs & Engines / JOGL Development / Re: How to achieve an animation of a 3D model?
|
on: 2009-07-18 18:12:56
|
Thanks for answering and the example! I will study it when I start learning about shaders (now I am just looking at the subject). Ah, I see, so the compilation of the OGSL code is done during runtime of the JOGL application by that OpenGL command, glCompileShader. What about compilation errors? How are they presented? Is it possible to achieve everything about shading just by using OpenGL than using a shader language? In your file simple.vert linked in your example code, what would be the OpenGL way to do that your vertex shader does: 1
| gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex * vec4 (0.7, 0.5, 0.5, 1.0); |
?
|
|
|
|
|
24
|
Java Game APIs & Engines / JOGL Development / Re: How to achieve an animation of a 3D model?
|
on: 2009-07-18 00:41:20
|
The .cg files are shader programs used to replace parts of the rendering with a custom written program. He's probably updating variables in that program so that it dynamically moves the vertices on a grid to appear as waves.
That being said, OpenGL comes with no support for animations. It is the programmer's responsibility to write code that can read the mesh and animation files created in Blender, etc. and use them. For animating, this might involve repeatedly computing new vertex positions on the CPU each frame, or you can write custom shaders to move that calculation onto the GPU.
Are those shader programs run by the JOGL application? If they are updating variables, how does the logic look like? It cannot update variables in the running Java application (right?), so it has to update variables and write them to some kind of file that is later read by the Java application. Is that the way of how it works? Which language is the best one to start with between "OpenGL Shading Language" and "C for Graphics"? Are the .cg files written in "C for Graphics"?
|
|
|
|
|
26
|
Java Game APIs & Engines / JOGL Development / Why does my lightning only works when pos. var. declared in display() method?
|
on: 2009-07-17 12:12:35
|
I have a frustrating problem. I want to light up the sphere, like when the sun lights up the moon. It works with this code: 1 2 3 4 5 6 7 8 9 10 11 12 13
| public void display(GLAutoDrawable drawable) { gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel (GL.GL_SMOOTH);
float light_position[] = { -5.0f, 7.0f, sunrise, 0.0f }; gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, FloatBuffer.wrap(light0_ambient)); gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, FloatBuffer.wrap(mat_specular)); gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, FloatBuffer.wrap(mat_shininess)); gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, FloatBuffer.wrap(light_position)); ... sunrise += 0.02f; ... |
If I place the line: 1
| float light_position[] = { -5.0f, 7.0f, sunrise, 0.0f }; |
outside the display() method so it becomes a class member, then the animation doesn´t work and the sun seems to be still. How come?
|
|
|
|
|
28
|
Java Game APIs & Engines / JOGL Development / Re: How to draw a 3D globe?
|
on: 2009-07-15 16:43:36
|
Hey, you also can put your LINE_LOOP in a DisplaylIst, then call it in a for next loop 360 times and rotate it around one axis, y-axis for example. Or just use the glut-method GlutWireSphere, glutSolidSphere?!?! Why not these? best regards, normen
But glut-methods are not a part of JOGL?
|
|
|
|
|
29
|
Java Game APIs & Engines / JOGL Development / How to draw a 3D globe?
|
on: 2009-07-14 18:43:10
|
I´m trying do draw a 3D globe, but don´t succeed. A circle is beeing drawn, but then I would like to draw circels each with 1 grade angle increase since the last drawn circle. What do I have to modify in my code? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| final float DEG2RAD = (float)3.14159/180; float grade = 0.0f;
void drawCircle(float radius) { gl.glBegin(GL.GL_LINE_LOOP);
for (int i=0; i < 360; i++) { for(int y=0; y<360; y++) { float degInRad = y*DEG2RAD; gl.glVertex2f(((float)Math.cos(degInRad)*radius)+grade, (float)Math.sin(degInRad)*radius); grade++; } }
gl.glEnd(); } |
|
|
|
|
|
30
|
Java Game APIs & Engines / JOGL Development / Re: How do I draw the same polygon in two different viewports?
|
on: 2009-07-14 18:10:47
|
I made a try but couldn´t get it working. Just the circles on the first viewpoint are beeing displayed, but not the one drawn after the second viewpoint has beeing specified. First I specified the first viewpoint in the reshape() method; 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
this.width = width; this.height = height;
gl.glViewport (0, 0, width/2, height); gl.glMatrixMode (GL.GL_PROJECTION); gl.glLoadIdentity (); glu.gluPerspective(60.0f, 3.0f, 1.0f, 20.0f); gl.glMatrixMode (GL.GL_MODELVIEW); gl.glMultMatrixf(new float[]{4.1f, 4.1f, 6.1f}, 0); gl.glLoadIdentity(); glu.gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); } |
Then I specified the other viewpoint in the display() method; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public void display(GLAutoDrawable drawable) { gl = drawable.getGL();
gl.glClear (GL.GL_COLOR_BUFFER_BIT); gl.glColor3f (1.0f, 1.0f, 1.0f); gl.glPushMatrix(); drawCircle(2.5f);
gl.glRotatef (year, 0.0f, 1.0f, 0.0f); gl.glTranslatef (2.0f, 0.0f, 0.0f); gl.glRotatef (day, 0.0f, 1.0f, 0.0f); drawCircle(1.5f);
gl.glPopMatrix();
gl.glViewport (width/2, 0, width/2, height); gl.glMatrixMode (GL.GL_PROJECTION); gl.glLoadIdentity (); glu.gluPerspective(60.0f, 3.0f, 1.5f, 20.0f); gl.glMatrixMode (GL.GL_MODELVIEW);
drawCircle(2.5f);
gl.glFlush (); } |
What have I missed?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|