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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Using OpenGL directly
Page Index Toggle Pages: 1
Using OpenGL directly (Read 1417 times)
Using OpenGL directly
Nov 29th, 2005, 1:24pm
 
I'm having trouble when trying to handle some direct OpenGL code in an sketch.

Using the processing versions works fine (and I assume calls the GL equivalent in the end anyway) I just wanted to try out hand crafting OpenGL stuff.

I've written a small sketch, that should display 4 white squares, one OpenGL, one Processing, one OpenGL display list and one Processing put inside a display list. However, only the two processing variants seem to actually be being shown, and I've no idea why.

The code is included below, and I'd be grateful if anyone could enlighten me as to why the OpenGL ones don't seem to be working as I expect them to.

Code:
import processing.opengl.*;
import net.java.games.jogl.*;

GL gl;
int p,q;

void setup()
{
size(300,300,OPENGL);
gl=((PGraphicsGL)g).gl;
buildquad();
}

void draw()
{
background(0);
// top left square
gl.glBegin(GL.GL_QUADS);
gl.glColor4f(1.0,1.0,1.0,1.0);
gl.glVertex3f(0.0,0.0,0.0);
gl.glVertex3f(100.0,0.0,0.0);
gl.glVertex3f(100.0,100.0,0.0);
gl.glVertex3f(0.0,100.0,0.0);
gl.glEnd();

//top right
beginShape(QUADS);
fill(255);
vertex(200,0,0);
vertex(300,0,0);
vertex(300,100,0);
vertex(200,100,0);
endShape();
gl.glCallList(p);
gl.glCallList(q);
}

void buildquad()
{
p=gl.glGenLists(1);
gl.glNewList(p,GL.GL_COMPILE);
// bottom left
gl.glBegin(GL.GL_QUADS);
gl.glColor4f(1.0,1.0,1.0,1.0);
gl.glVertex3f(0.0,200.0,0.0);
gl.glVertex3f(100.0,200.0,0.0);
gl.glVertex3f(100.0,300.0,0.0);
gl.glVertex3f(0.0,300.0,0.0);
gl.glEnd();
gl.glEndList();
q=gl.glGenLists(1);
gl.glNewList(q,GL.GL_COMPILE);
//bottom right
beginShape(QUADS);
vertex(200,200,0);
vertex(300,200,0);
vertex(300,300,0);
vertex(200,300,0);
endShape();
gl.glEndList();
}
Re: Using OpenGL directly
Reply #1 - Nov 29th, 2005, 3:24pm
 
most opengl code won't work directly because of how we have to set up rendering. just about everything is processed by PGraphics3 before being sent to opengl, meaning that matrices won't be set up correctly for opengl.
Re: Using OpenGL directly
Reply #2 - Nov 29th, 2005, 8:15pm
 
i just went to add this to the faq, but in fact it's already there:
http://processing.org/faq/bugs.html#opengl
Re: Using OpenGL directly
Reply #3 - Dec 14th, 2005, 6:32am
 
ya, anywayz, here's a nice function for you that fixes your code.  It's called "beginRawGL()" and it makes the other 2 squares draw, but breaks the P engine til the end of the draw call. So make sure you do all your P-ing before you go raw. Someone please write a function to get back out from this mode. -JT

----------------

import processing.opengl.*;
import net.java.games.jogl.*;
GL gl;
int p,q;


void beginRawGL(){
/*
 * escape Fry's matrix to make raw jogl calls work
 * til the end of the draw function.
 * special thanks to Flux for showing me this thread.
 * love always, your pal Josh Nimoy
 */
 gl.glViewport(0,0,width,height);
 gl.glMatrixMode(GL.GL_PROJECTION);
 gl.glLoadIdentity();                                                                                                                                                  
 gl.glMatrixMode(GL.GL_MODELVIEW);                                                                                                                                        
 gl.glLoadIdentity();
 gl.glTranslatef(-1,1,0);
 gl.glScalef(2.0/width,-2.0/height,0);
}








void setup()
{
 size(300,300,OPENGL);
 gl=((PGraphicsGL)g).gl;
 buildquad();
}

   
   
void draw()
{
background(0);

//top right
 beginShape(QUADS);
 fill(255);
 vertex(200,0,0);
 vertex(300,0,0);
 vertex(300,100,0);
 vertex(200,100,0);
 endShape();
 gl.glCallList(q);

 beginRawOpenGL();
 
 // top left square
 gl.glBegin(GL.GL_QUADS);
 gl.glColor4f(1.0,1.0,1.0,1.0);
 gl.glVertex3f(0.0,0.0,0.0);
 gl.glVertex3f(100.0,0.0,0.0);
 gl.glVertex3f(100.0,100.0,0.0);
 gl.glVertex3f(0.0,100.0,0.0);
 gl.glEnd();


 gl.glCallList(p);
}

void buildquad()
{
 p=gl.glGenLists(1);
 gl.glNewList(p,GL.GL_COMPILE);
// bottom left
 gl.glBegin(GL.GL_QUADS);
 gl.glColor4f(1.0,1.0,1.0,1.0);
 gl.glVertex3f(0.0,200.0,0.0);
 gl.glVertex3f(100.0,200.0,0.0);
 gl.glVertex3f(100.0,300.0,0.0);
 gl.glVertex3f(0.0,300.0,0.0);
 gl.glEnd();
 gl.glEndList();
 q=gl.glGenLists(1);
 gl.glNewList(q,GL.GL_COMPILE);
//bottom right
 beginShape(QUADS);
 vertex(200,200,0);
 vertex(300,200,0);
 vertex(300,300,0);
 vertex(200,300,0);
 endShape();
 gl.glEndList();
}
Re: Using OpenGL directly
Reply #4 - Dec 15th, 2005, 10:45am
 
opengl offers a mechanism that lets you save other opengl states the same way you can save the matrix states.

Code:

/* store opengl states */
gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);

/* restore opengl states */
gl.glPopAttrib();


this should prevent most things from breaking.

on another tangent, you might want to check out gestalt. it s an environment we created for developing opengl sketches and applications.

just recently we put together a processing plugin/library which is pretty straight forward. i havn t released it officially yet, due to a lack of documentation and examples. but i m still positive it will happen soon.
Page Index Toggle Pages: 1