Well here's the whole code, mostly created from that german tutorial. (babel fish is nice)
thx for the other info.
import java.awt.Color;
import java.util.Random;
import java.util.Date;
import java.nio.ByteBuffer;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.GL11;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.glu.GLU;
import org.lwjgl.opengl.OpenGLException;
public class JavaLWJGL2
{
private DisplayMode displayMode = null;
private String title;
private int width = 320;
private int height = 240;
private byte[] fire = new byte[width*height*3];
private ByteBuffer pixels;
private int pos_y = 100;
public JavaLWJGL2(String title)
{
this.title = title;
randomizeFire();
pixels = ByteBuffer.allocateDirect(width*height*3).put(fire);
pixels.flip();
}
public void init()
{
initWindow();
initKeyboard();
initOpenGL();
reSizeGLScene(displayMode.getWidth(), displayMode.getHeight());
run();
}
private void initWindow()
{
try
{
displayMode = org.lwjgl.util.Display.getAvailableDisplayModes(
800,600,800,600,32,32,60,60)[0];
Display.setDisplayMode(displayMode);
Display.setFullscreen(false);
Display.create();
Display.setTitle(title);
}
catch(LWJGLException e){System.out.println(e);}
}
private void initKeyboard()
{
try
{
if (!Keyboard.isCreated())
Keyboard.create();
}
catch(LWJGLException e){System.out.println(e);}
}
private void initOpenGL()
{
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glClearColor(0.0f,0.0f,0.0f,0.0f);
GL11.glClearDepth(1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,GL11.GL_NICEST);
}
private void reSizeGLScene(int width, int height)
{
if (height == 0)
height = 1;
GL11.glViewport(0,0,width,height); // aktuellen viewport zurücksetzen
GL11.glMatrixMode(GL11.GL_PROJECTION); // Projection Matrix (PM) auswählen
GL11.glLoadIdentity(); // PM zurücksetzen
GLU.gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f); // 45° Perspektive
GL11.glMatrixMode(GL11.GL_MODELVIEW); // ModelView Matrix (MVM) auswählen
GL11.glLoadIdentity(); // MVM zurücksetzen
}
//make some random colored pixels
private void randomizeFire()
{
Random rand = new Random(new Date().getTime());
for(int i=0; i<fire.length;i++)
fire[i] = (byte)rand.nextInt(256);
}
private void renderGLScene()
{
randomizeFire();
GL11.glRasterPos2i(10,pos_y+10);
GL11.glDrawPixels(width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, pixels);
}
private void cleanup()
{
destroyWindow();
System.exit(0);
}
private void destroyWindow()
{
if (Display.isCreated())
Display.destroy();
}
private void checkKeyboardInput()
{
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
cleanup();
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
pos_y -= 1;
if (Keyboard.isKeyDown(Keyboard.KEY_UP))
pos_y += 1;
}
private void run()
{
while(true)
{
if(Display.isCloseRequested())
{
cleanup();
break;
}
if(Display.isVisible() || Display.isDirty())
{
try
{
renderGLScene();
Display.update();
}
catch(OpenGLException e){System.out.println(e);}
}
checkKeyboardInput();
}
}
public static void main()
{
JavaLWJGL2 prog = new JavaLWJGL2("Java with Open GL");
prog.init();
}
}