calling LWJGL methods directly

Started by raft, March 30, 2009, 08:29:40 AM

Previous topic - Next topic

raft

hello,

what should i do to call opengl methods directly after jPCT has done ? for example the code below doesnt draw a line


while (loop) {
    // do jPCT things
    world.renderScene(buffer);
    world.draw(buffer);
    buffer.update();

    // do lwjgl things
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2f(10, 10);
    GL11.glVertex2f(50, 50);
    GL11.glEnd();

    buffer.displayGLOnly();
    Thread.sleep(10);
}

EgonOlsen

Hmmm...looks fine to me. If it doesn't work out, you may try to wrap your code into an IPostProcessor instead.

raft

onfortunately didnt help  ??? this is version 1.17

buffer.addPostProcessor(new IPostProcessor(){
private boolean initialized = false;

public void dispose() {
initialized = false;
}

public void init(FrameBuffer buffer) {
initialized = true;
}

public boolean isInitialized() {
return initialized;
}

public void process() {
GL11.glColor3f(255, 255, 255);
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2f(10, 10);
GL11.glVertex2f(50, 50);
GL11.glEnd();

}
});

EgonOlsen

Which renderer is this? GL or AWTGL?

raft

GL. just a simple addition to HelloWorldOGL sample

EgonOlsen

Have you tried to add a


GL11.glDisable(GL11.GL_DEPTH_TEST);


before and a

GL11.glEnable(GL11.GL_DEPTH_TEST);

after your code?

raft

didnt help neither  ??? i know nothing about opengl so i may be forgotting something stupid.. does it work for you ?


EgonOlsen

This works:


GL11.glMatrixMode(GL11.GL_MODELVIEW);
       GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glOrtho(0, 1, 1, 0, 0.1, 100);
   
      GL11.glColor3f(255, 255, 255);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      GL11.glBegin(GL11.GL_LINES);
      GL11.glVertex3f(0.0f, 0.0f, -1f);
      GL11.glVertex3f(1.0f, 1.0f, -1f);
      GL11.glEnd();
      GL11.glEnable(GL11.GL_TEXTURE_2D);
     
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPopMatrix();
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glPopMatrix();


i.e. switch to Ortho-mode, use normalized screen coordinates and disable texturing.

raft

that worked for me too  ;D but are all that stuff necessary ? and why glVertex3f ? i tried different z values, seems as a negative value is necessary but why ?

sorry, i know this is not a jPCT thing but  ::)

EgonOlsen

It's required to give it a z-value that won't be clipped. I'm sure it's possible to set up OpenGL in a way that this isn't needed anymore, but that would require even more state changes before and after. Ortho mode is required, because otherwise the normal perspective transformations apply for your line, which isn't what you want for a 2d line.

raft

i see thank you :D and i guess this is the way to set it it up for 2D: (looking at FengGui source)
GLU.gluOrtho2D(0, 800, 600, 00);

EgonOlsen

I still prefer the normalized coordinates. If you want to get rid of the z-value, try this instead:


GL11.glOrtho(0, 1, 1, 0, 0.0f, 0.1f);


In addition, this doesn't force you to include GLU.

raft

indeed i need exact coordinates. so will it be like
GL11.glOrtho(0, width, height, 0, 0.0f, 0.1f);

EgonOlsen

Quote from: raft on March 30, 2009, 11:13:26 AM
indeed i need exact coordinates. so will it be like
GL11.glOrtho(0, width, height, 0, 0.0f, 0.1f);
In that case, yes!

raft

that code makes y axis increase downwards. is it also possible to convert mouse coordinate system ?