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
OpenGL drawing (Read 698 times)
OpenGL drawing
Feb 27th, 2008, 11:54am
 
Hello all

I'm currently trying to learn the basics of OpenGL programing. I know what i'm trying to do can be achieved with the core processing methods but i want to try and get my head round whats happening under the hood.

So in the below code i have a display list which is attempting to draw a red rectangle on the stage (to pardon the flash term).  With this code nothing happens... i get a black screen.

Code:

void draw()
{

background(0.5f);

gl.glPushMatrix();
gl.glCallList(squareList);
gl.glPopMatrix();

}


Doing a bit of digging about i find some code and change it to:

Code:

void draw()
{

gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(50.0, 1.0, 3.0, 7.0);

gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

gl.glPushMatrix();
gl.glCallList(squareList);
gl.glPopMatrix();


}


..which displays my code correctly.

Now I've been through various code references and generally know what this code does. My questions are:

1) do i always need to set default matrices for GL_MODELVIEW and GL_PROJECTION and if so why?

2)do i always need to set a perspective in this way (I thought there was a default perspective set in processing)?

3) do i always need to set a gluLookAt (which i assume is some sort of camera function)?  

I just want to get my head round what this exactly is and why it is needed.

Any pointer appreciated.

Cheers
James
Re: OpenGL drawing
Reply #1 - Feb 27th, 2008, 1:56pm
 
this may help, you have to fetch the gl context from PGraphicsOpenGL with beginGL() to make use of the initial opengl settings of processing.

Code:


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

GL gl;
PGraphicsOpenGL pgl;
int squareList;

void setup() {
size(900,600,OPENGL);
pgl = (PGraphicsOpenGL)g;
gl = pgl.gl;
squareList = gl.glGenLists(1);
gl.glNewList(squareList, GL.GL_COMPILE);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(0,0,0);
gl.glVertex3f(100,0,0);
gl.glVertex3f(100,100,0);
gl.glVertex3f(0,100,0);
gl.glEnd();
gl.glEndList();
}

void draw() {
background(0);
// fetch the gl context from pgl
gl = pgl.beginGL();
// do your gl stuff
gl.glPushMatrix();
gl.glTranslatef(width/2, height/2,0);
gl.glCallList(squareList);
gl.glPopMatrix();
// close pgl's gl context
pgl.endGL();
}


Re: OpenGL drawing
Reply #2 - Feb 27th, 2008, 3:26pm
 
Cheers sojamo... i do have all that setup stuff and have created the display list so all was good.

All it was was that my vertex values were too small to see (i think) with the default perspective. I was working from a C tutorial so all is well.

Page Index Toggle Pages: 1