LWJGL Forum
Programming => OpenGL => Topic started by: white waluigi on March 23, 2013, 11:35:23
-
I'd like to make a little 2d game with lwjgl and Opengl.
The Problem is, that whenever i resize the Window, the content won't resize and just staysthe old size.
Thats my current code:
I just can't see the fault.
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class QuadExample {
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
Display.setResizable(true);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// init OpenGL
System.out.print(Math.sqrt(4));
while (!Display.isCloseRequested()) {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
// set the color of the quad (R,G,B,A)
GL11.glColor3f(0.5f,0.5f,1.0f);
// draw quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(10,10);
GL11.glVertex2f(Display.getWidth()-10,10);
GL11.glVertex2f(Display.getWidth()-10,Display.getHeight()-10);
GL11.glVertex2f(10,Display.getHeight()-10);
GL11.glEnd();
Display.update();
}
Display.destroy();
}
public static void main(String[] argv) {
QuadExample quadExample = new QuadExample();
quadExample.start();
}
}
-
You aren't setting the viewport. You have to set the viewport to tell OpenGL where it should be drawing. You use the glViewport command which takes 4 params: x, y, width, height. x and y are relative to the position of the Display so every time the display gets resized, you need to call glViewport(0, 0, Display.getWidth(), Display.getHeight());
-
Thanks, helped me alot.
Have a nice weekend
-
I already am. Thankyou, have a good one yourself.
It's nice to see someone using their time being pleasant to another.