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
gluSphere (Read 2532 times)
gluSphere
Dec 4th, 2006, 10:12pm
 
hey folks,

i want do draw a sphere with the glut framework. the jogl i already got and either i imported the libraries:

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

with the following code i wanted to draw my sphere:
GLU glu = new GLU();
GLUquadric qobj0 = glu.gluNewQuadric();
glu.gluSphere(qobj0, 1, 64, 64);

but it doesn't work. i get a GLexception like this:
javax.media.opengl.GLException: No OpenGL context current on this thread

.. and now i don't know any further? how can i work with gl and glu commands together?

for using "common" opengl commands the following is needed:
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
// my commands here
pgl.endGL();

and unfortunatelly GLU glu = pgl.beginGLU() doesn't work Sad

can anybody help me outta here?

thx in advance,
manunu
Re: gluSphere
Reply #1 - Dec 5th, 2006, 12:04am
 
You're creating your GL/GLU objects wrongly. one of each has already been created, and set-up properly when you call size(123 ,123 , OPENGL);, you just need to create a local variable to make access to it easier.

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

GL gl;
GLU glu;

void setup()
{
size(800,600,OPENGL);
gl=((PGraphicsOpenGL)g).gl;
glu=((PGraphicsOpenGL)g).glu;
}


HOWEVER, and this is a big however, processing does some fiddling in between what you write, and what appears on screen, so it is NOT possible to simply run both processing commands and GL commands side by side, things will appear in the wrong places, look bad, and cause various other oddities. There are ways around it, but it's not easy.
Re: gluSphere
Reply #2 - Dec 5th, 2006, 9:29am
 
thx for the fast help!
it kind of works now (don't get any more errors), but i'm not able to draw anything.

void setup()
{
 size(800,400,OPENGL);
 gl=((PGraphicsOpenGL)g).gl;
 glu=((PGraphicsOpenGL)g).glu;
 background (255);
}

void draw () {
 GLUquadric qobj0 = glu.gluNewQuadric();
 glu.gluSphere(qobj0, 1, 64, 64);
}

i just see my black background. do i have to declare some kind of block like i have to do with "common"opengl commands?
this thing here:
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
    GL gl = pgl.beginGL();
    ...
    pgl.endGL();

? i'm really stuck... Sad

greets, manunu
Re: gluSphere
Reply #3 - Dec 5th, 2006, 10:58am
 
manunu wrote on Dec 5th, 2006, 9:29am:
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
    GL gl = pgl.beginGL();
    ...
    pgl.endGL();

I've no idea where you've got that above code from, but it's cmopletely wrong and it'll never work as none of those functions exist.

You can't just do pure GL/GLU functions in Processing. Processing does some munging behind the scenes that mean it wont work.

You may be able to do it if you find the ProGL library for Processing, but I've not used it so I'm not sure.
Re: gluSphere
Reply #4 - Dec 5th, 2006, 11:43am
 
the little code fragment above with the PGraphicsOpenGL thing is from the processing reference site, where the use of "gl." commandos is described. therefore i used this pgl.beginGl() and pgl.endGl() for "common" openGL commandos.

so how can i get my glu.gluSphere(...) working?

thx, manunu
Re: gluSphere
Reply #5 - Dec 5th, 2006, 12:01pm
 
problem solved...

my stupid sphere was always too small..
so that was/is the working code from my draw-method:

void draw () {

 background(255);
 PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
 GL gl = pgl.beginGL();
 
    GLUquadric qobj0 = glu.gluNewQuadric();
    gl.glColor4f(0.7, 0.7, 0.7, 0.8);
    gl.glTranslatef(width/2, height/2, 0);
    glu.gluSphere(qobj0, 100, 64, 64);
 
 
 pgl.endGL();
}

thx anyway for the help!

greets, manu
Re: gluSphere
Reply #6 - Dec 5th, 2006, 12:44pm
 
Ah, I was confused since I think beginGL is a new feature of processing's that's not been advertised anywhere that I can tell.

Looks useful though.
Re: gluSphere
Reply #7 - Dec 5th, 2006, 1:58pm
 
see advertisement in the reference:
http://processing.org/reference/libraries/opengl/index.html
Re: gluSphere
Reply #8 - Dec 5th, 2006, 3:59pm
 
Ah so it is. That completely passed me by.

I know it says things will probably go wrong, and we shouldn't use processing as a java/GL tool, but it works fairly well. I stripped my custom GL library out of a sketch, changed a couple of things, and it seems to work very well. (though I do no processing based fcuntions, only GL ones)

( http://www.hardcorepawn.com/CowCatcher/ for anyone interested )
Page Index Toggle Pages: 1