We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
JOGL for dummies (Read 1849 times)
JOGL for dummies
Jul 20th, 2009, 4:02am
 
Hi, can you help me to understand this, basically I just trow an arrow here to see what happens, obviously nothing...

I try to follow this tutorial http://jerome.jouvie.free.fr/OpenGl/Tutorials/Tutorial4.php

but I am missing something, can you tell me how to get this sample working, and what I am doing wrong?
Code:
import javax.media.opengl.*;
import processing.opengl.*;

void setup() {
 size(800, 600, OPENGL);
}

void draw() {
 background(255);

 PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
 GL gl = pgl.beginGL();
 gl.glBegin(GL.GL_TRIANGLE_FAN);
   gl.glColor3f(1.0f,0.0f,0.0f);
   gl.glVertex3f( 0.0f, 1.0f, 0.0f);
   gl.glColor3f(0.0f,1.0f,0.0f);
   gl.glVertex3f(-1.0f,-1.0f, 1.0f);
   gl.glColor3f(0.0f,0.0f,1.0f);
   gl.glVertex3f( 1.0f,-1.0f, 1.0f);
   gl.glColor3f(0.0f,1.0f,0.0f);
   gl.glVertex3f( 1.0f,-1.0f,-1.0f);
   gl.glColor3f(0.0f,0.0f,1.0f);
   gl.glVertex3f(-1.0f,-1.0f,-1.0f);
   gl.glColor3f(0.0f,1.0f,0.0f);
   gl.glVertex3f(-1.0f,-1.0f, 1.0f);
 gl.glEnd();
 pgl.endGL();

}


Please note that I have no idea of JOGL, OPENGL at all

Cheers
rS
Re: JOGL for dummies
Reply #1 - Jul 20th, 2009, 5:20am
 
it's missing a bit of camera setup

Quote:
import javax.media.opengl.*;
import processing.opengl.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;

GLU glu = new GLU();

void setup() {
  size(800, 600, OPENGL);
}

void draw() {
  background(0);

  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
  GL gl = pgl.beginGL();

  gl.glMatrixMode( GL.GL_PROJECTION );
  gl.glLoadIdentity();
  glu.gluPerspective( 45.0, (float)width/(float)height, 0.1, 10000.0 );
  gl.glMatrixMode( GL.GL_MODELVIEW );
  gl.glLoadIdentity();
  glu.gluLookAt( 0.0, 1.0, 10.0,  // position
  0.0, 0.0, 0.0,                  // interest
  0.0, 1.0, 0.0 );                // upvector

  gl.glBegin(GL.GL_TRIANGLE_FAN);
  gl.glColor3f(1.0f,0.0f,0.0f); 
  gl.glVertex3f( 0.0f, 1.0f, 0.0f);
  gl.glColor3f(0.0f,1.0f,0.0f); 
  gl.glVertex3f(-1.0f,-1.0f, 1.0f);
  gl.glColor3f(0.0f,0.0f,1.0f); 
  gl.glVertex3f( 1.0f,-1.0f, 1.0f);
  gl.glColor3f(0.0f,1.0f,0.0f); 
  gl.glVertex3f( 1.0f,-1.0f,-1.0f);
  gl.glColor3f(0.0f,0.0f,1.0f); 
  gl.glVertex3f(-1.0f,-1.0f,-1.0f);
  gl.glColor3f(0.0f,1.0f,0.0f); 
  gl.glVertex3f(-1.0f,-1.0f, 1.0f);
  gl.glEnd();
  pgl.endGL();


Re: JOGL for dummies
Reply #2 - Jul 20th, 2009, 5:29am
 
Hi, that is good it works fine, but why that camera setup is not present in this code and it still renders fine?

Code:
import javax.media.opengl.*;
import processing.opengl.*;

float a;

void setup() {
 size(800, 600, OPENGL);
}

void draw() {
 background(255);
 
 PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
 GL gl = pgl.beginGL();
 
 gl.glColor4f(0.7, 0.7, 0.7, 0.8);
 gl.glTranslatef(width/2, height/2, 0);
 gl.glRotatef(a, 1, 0, 0);
 gl.glRotatef(a*2, 0, 1, 0);
 gl.glRectf(-200, -200, 200, 200);
 gl.glRotatef(90, 1, 0, 0);
 gl.glRectf(-200, -200, 200, 200);
 
 pgl.endGL();
 
 a += 0.5;
}


That code is a sample code from the processing opengl library page

Cheers
rS
Re: JOGL for dummies
Reply #3 - Jul 20th, 2009, 5:47am
 
You need to learn how the modelview matrix works.
You can think of that in terms of cameras or in terms objects or both.
In my code I usually prefer to setup the camera first, using a lookat, and then I place the objects, but it's not a rule.
In that example, gl.glTranslatef is used to change the modelview matrix (that's the matrix you're changing by default)

To be completely clear: the first code you posted it's working and rendering, but you can't see it because the triangles might be behind the camera (or beyond the znear / zfar limits)
Re: JOGL for dummies
Reply #4 - Jul 20th, 2009, 6:02am
 
Brilliant!

Thanks for the explanation, do you now any good JOGL Processing tutorials, link, ect?

rS
Re: JOGL for dummies
Reply #5 - Jul 20th, 2009, 7:04am
 
The usual ones: gamedev.net, opengl.org, lighthouse3d.com, the red book, the orange book, etc.
Btw don't look for JOGL processing tutorials unless you need something specific to OpenGL integration within processing. Look for OpenGL tutorials instead.
-m
Page Index Toggle Pages: 1