www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: raft on March 30, 2009, 08:29:40 am

Title: calling LWJGL methods directly
Post by: raft on March 30, 2009, 08:29:40 am
hello,

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

Code: [Select]

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);
}
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 09:36:57 am
Hmmm...looks fine to me. If it doesn't work out, you may try to wrap your code into an IPostProcessor instead.
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 09:49:29 am
onfortunately didnt help  ??? this is version 1.17

Code: [Select]
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();

}
});
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 10:00:37 am
Which renderer is this? GL or AWTGL?
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 10:03:58 am
GL. just a simple addition to HelloWorldOGL sample
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 10:23:06 am
Have you tried to add a

Code: [Select]
GL11.glDisable(GL11.GL_DEPTH_TEST);

before and a

Code: [Select]
GL11.glEnable(GL11.GL_DEPTH_TEST);
after your code?
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 10:29:28 am
didnt help neither  ??? i know nothing about opengl so i may be forgotting something stupid.. does it work for you ?

Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 10:45:00 am
This works:

Code: [Select]
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.
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 10:54:53 am
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  ::)
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 10:57:37 am
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.
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 11:06:35 am
i see thank you :D and i guess this is the way to set it it up for 2D: (looking at FengGui source)
Code: [Select]
GLU.gluOrtho2D(0, 800, 600, 00);
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 11:10:18 am
I still prefer the normalized coordinates. If you want to get rid of the z-value, try this instead:

Code: [Select]
GL11.glOrtho(0, 1, 1, 0, 0.0f, 0.1f);

In addition, this doesn't force you to include GLU.
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 11:13:26 am
indeed i need exact coordinates. so will it be like
Code: [Select]
GL11.glOrtho(0, width, height, 0, 0.0f, 0.1f);
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 11:16:02 am
indeed i need exact coordinates. so will it be like
Code: [Select]
GL11.glOrtho(0, width, height, 0, 0.0f, 0.1f);
In that case, yes!
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 02:11:51 pm
that code makes y axis increase downwards. is it also possible to convert mouse coordinate system ?
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 03:55:07 pm
that code makes y axis increase downwards. is it also possible to convert mouse coordinate system ?
Which is natural IMHO. If you want it reversed, just do something like this:

Code: [Select]
GL11.glOrtho(0, 800, 0, 600, 0.0f, 0.1f);
Title: Re: calling LWJGL methods directly
Post by: raft on March 30, 2009, 07:56:50 pm
Quote
Which is natural IMHO. If you want it reversed, just do something like this:
Code: [Select]
GL11.glOrtho(0, 800, 0, 600, 0.0f, 0.1f);
no, i'm happy it reverses Y coordinate. i just wonder if same can be done for lwjgl Mouse class ?
Title: Re: calling LWJGL methods directly
Post by: EgonOlsen on March 30, 2009, 08:08:38 pm
no, i'm happy it reverses Y coordinate. i just wonder if same can be done for lwjgl Mouse class ?
I don't really know, but i don't think so.