Author Topic: calling LWJGL methods directly  (Read 5428 times)

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
calling LWJGL methods directly
« 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);
}

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #1 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.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #2 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();

}
});

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #3 on: March 30, 2009, 10:00:37 am »
Which renderer is this? GL or AWTGL?

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #4 on: March 30, 2009, 10:03:58 am »
GL. just a simple addition to HelloWorldOGL sample

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #5 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?

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #6 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 ?


Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #7 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.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #8 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  ::)

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #9 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.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #10 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);

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #11 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.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #12 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);

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: calling LWJGL methods directly
« Reply #13 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!

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: calling LWJGL methods directly
« Reply #14 on: March 30, 2009, 02:11:51 pm »
that code makes y axis increase downwards. is it also possible to convert mouse coordinate system ?