Rendering a textured quad in LWJGL is rendering White? - java

I am trying to render a textured quad onto the screen as a start menu button for my new game. But when rendering it just renders as a white quad, i have searched for days over the internet and i havent found a single answer that has fixed the problem.
My texture is wood.png and it is in a "res" folder inside a resources source folder in the project. it is a 128 * 128 pixel image.
The code for rendering textures is as follows:
public static void renderTexture(Texture texture, float width, float height, float x, float y) {
texture.bind();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
texture.bind();
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
glLoadIdentity();
glEnd();
glDisable(GL_BLEND);
}
The code that i use to load the textures is:
public static Texture loadTexture(String fileName){
try {
Texture texture = TextureLoader.getTexture("PNG",Class.class.getResourceAsStream("/res/"+fileName+".png"));
return texture;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I have a static Texture storing private static Texture startTex = Loader.loadTexture("wood"); and i render it every frame by doing:
RenderSystem.renderTexture(startTex, 200, 200, 0, 0);

The Answer is that i did glBegin(GL_TEXTURE_2D); instead of glEnable(GL_TEXTURE_2D);
Sorry the code for that part wasnt shown.

Related

Why does my drawRect code always displays black

This is my drawRect code:
public static void drawRect(float X, float Y, float WIDTH, float HEIGHT, float RED, float GREEN, float BLUE)
{
// 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(RED, GREEN, BLUE);
// draw quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(X,Y);
GL11.glVertex2f(X+WIDTH,Y);
GL11.glVertex2f(X+WIDTH,Y+HEIGHT);
GL11.glVertex2f(X,Y+HEIGHT);
GL11.glEnd();
}
This is what i'm doing
Renderer.drawRect(0, 0, Display.getWidth(), Display.getHeight(), 255, 255, 255);
It fills the entire screen (like it should) but the color is always black.
I suggested reading tutorials because glColor3f() expects 3 floats in the 0...1 range for color components, just like most accelerated graphics API-s. And if this one slipped, there may be confusion about other details too. But nevertheless, 255 would be still clamped to 1, so the routine does not draw a black rectangle, something is missing before (in the setup) and/or after (like a call making the drawing actually appear on screen).
LWJGL wiki has a complete example code for exactly what you are trying to do, by the way: http://wiki.lwjgl.org/wiki/LWJGL_Basics_3_(The_Quad).html
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();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// init OpenGL
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 0, 600, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
while (!Display.isCloseRequested()) {
// 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(100,100);
GL11.glVertex2f(100+200,100);
GL11.glVertex2f(100+200,100+200);
GL11.glVertex2f(100,100+200);
GL11.glEnd();
Display.update();
}
Display.destroy();
}
public static void main(String[] argv) {
QuadExample quadExample = new QuadExample();
quadExample.start();
}
}

LWJGL text problems and framerate drops

in LWJGL I add text to my Display. When done, the program drops to about 1-2FPS. I have capped it with Display.sync(60);
Without text, it runs fine. With, absolutely... terrible?
Here is the source for my text:
import java.awt.Font;
import java.io.InputStream;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.util.ResourceLoader;
public class Text {
private TrueTypeFont font2;
public void drawString(String font, String string, int x, int y, Color color) {
// TODO: Fix extreme lag issues.
try {
InputStream inputStream = ResourceLoader.getResourceAsStream(font);
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
awtFont = awtFont.deriveFont(24f); // set font size
font2 = new TrueTypeFont(awtFont, false);
Color.white.bind();
font2.drawString(x, y, string, color);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Dont exactly want to release my games source but heres the code that displays the text.
// Initialization code OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Text t = new Text();
t.drawString("res/Minecraftia.ttf", "test", 0, 0, Color.yellow);
Edit:
// Initialization code OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);
while (!Display.isCloseRequested()) {
// Render
init();
input();
grid.draw();
drawSelectionBox();
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
private void init() {
// This is what i'm meant to do????
Text t = new Text();
t.drawString("res/Minecraftia.ttf", "test", 0, 0, Color.white);
}
Edit again: (Hope not too long)
public Boot() {
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setTitle("Test Program.");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
grid = new BlockGrid();
// Initialization code OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);
init();
input();
grid.draw();
drawSelectionBox();
Display.update();
Text t = new Text();
t.drawString("res/Minecraftia.ttf", "test", 0, 0, Color.white);
while (!Display.isCloseRequested()) {
// Render
init();
input();
grid.draw();
drawSelectionBox();
//Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
Because you read the whole font and create it in every render call.
public void drawString(String font, String string, int x, int y, Color color) {
try {
//You create a new resource stream and load a file
InputStream inputStream = ResourceLoader.getResourceAsStream(font); // <-- slow
//You create a new Fonts and load it out of the input stream
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream); // <-- extremely slow
//You create a new TrueTypeFont out of it
awtFont = awtFont.deriveFont(24f); // set font size
font2 = new TrueTypeFont(awtFont, false); // <-- slow
Color.white.bind();
font2.drawString(x, y, string, color);
} catch (Exception e) {
e.printStackTrace();
}
}
Instead, you should do the Font-loading only once in an init call and then just refer to the TrueTypeFont when rendering.
Remember that rendering is a very performance sensitive call and creating instances or streams and loading in that method (and in update(..), too) can drastically drop your FPS rate and should be avoided.
Update
Furthermore, you are creating a new instance of Text every rendering call too:
Text t = new Text();
t.drawString("res/Minecraftia.ttf", "test", 0, 0, Color.yellow);
Here too, create this once in the beginning or, better, just pass the String to draw to the drawString method instead of having a wrapper object like Text for that.

More problems with Slick, LWJGL textures

So I have successfully imported textures into my game, but they are upside down, distorted and also off-centre.
The code can also be found here: http://pastebin.com/nvWMZqpX
If anyone could help it would be greatly appreciated.
public class Main {
private Texture sky;
public Main() {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("Spark");
Display.create();
sky = TextureLoader.getTexture("PNG", new FileInputStream(new File("resources/textures/sky.png")));
while(!Display.isCloseRequested()) {
setCamera();
sky.bind();
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3d(1, 1, 1);
glTexCoord2f(1, 0);
glVertex2i(640, 0);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(0, 1);
glVertex2i(0, 480);
glTexCoord2f(0, 1);
glVertex2i(0, 480);
glTexCoord2f(1, 1);
glVertex2i(640, 640);
glTexCoord2f(1, 0);
glVertex2i(640, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
Display.update();
Display.sync(60);
}
sky.release();
Display.destroy();
} catch (LWJGLException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Main();
}
public static void setCamera() {
//Clear Screen
glClear(GL_COLOR_BUFFER_BIT);
//Modifying the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 0, 480, -1, 1);
//Modify modelviewing matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
}
Is your texture a power of 2 (POT) image? (for example 512x512 pixels). This could be the cause of the distortion.
Also try inverting your texcoord arguments. This would fix the upside down part.
I might also noticed a wrong argument
glTexCoord2f(1, 1);
glVertex2i(640, 0);
glTexCoord2f(0, 1);
glVertex2i(0, 0);
glTexCoord2f(0, 0);
glVertex2i(0, 480);
glTexCoord2f(0, 0);
glVertex2i(0, 480);
glTexCoord2f(1, 0);
glVertex2i(640, 480); // <--- this line was 640,640?
glTexCoord2f(1, 1);
glVertex2i(640, 0);
Texture coordinates in openGL are handled upside down like this:
(source: learnopengles.com)

GLSurfaceView working on Android < 4.2 but Black Screen on > 4.2

Following code works perfectly on older Android versions, but only shows a black screen on newer versions (I guess 4.2 and higher).
Im very new to OpenGL and I used to work with Canvas/SurfaceView, but now I need GLSurfaceView for the performance, so I leeched some code from here and there without exactly knowing what it does. I didnt start a whole new project, I just rewrote some of my "Canvas-Code" to a GLSurfaceView loop. Thats why it might look strange and inefficient.
Explanation for the code:
The class "Sprite" contains a Bitmap, xPos and yPos. In "defineStuff();" I append a few different "Sprites" to a List and the GLSurfaceView draws everything from the List.
This is not the whole code, I removed pretty much to make it more clear.
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //so its Fullscreen
defineStuff();
glSurfaceView = new GLSurfaceView(this);
glSurfaceView.setRenderer(new GlRenderer());
glSurfaceView.setOnTouchListener(this);
setContentView(glSurfaceView);
}
The Sprite class:
public class Sprite {
private FloatBuffer vertexBuffer; // buffer holding the vertices
private FloatBuffer textureBuffer; // buffer holding the texture coordinates
private float texture[];
private float vertices[];
public Bitmap bmp;
public boolean visible;
public String name;
public float posX;
public float posY;
public Sprite(String name, Bitmap bitmap, float posX, float posY, boolean visible) {
this.name = name;
this.visible = visible;
setBuffers(bitmap, posX, posY);
}
public void setBuffers(Bitmap bitmap, float posX, float posY) {
bmp = bitmap;
}
this.posX = posX;
this.posY = posY;
float tempVertices[] = {
posX, posY + bitmap.getHeight(), 0.0f, // V1 - bottom left
posX, posY, 0.0f, // V2 - top left
posX + bitmap.getWidth(), posY + bitmap.getHeight(), 0.0f, // V3 - bottom right
posX + bitmap.getWidth(), posY, 0.0f // V4 - top right
};
vertices = new float[tempVertices.length];
System.arraycopy(tempVertices, 0, vertices, 0, tempVertices.length);
// a float has 4 bytes so we allocate for each coordinate 4 bytes
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
// allocates the memory from the byte buffer
vertexBuffer = byteBuffer.asFloatBuffer();
// fill the vertexBuffer with the vertices
vertexBuffer.put(vertices);
// set the cursor position to the beginning of the buffer
vertexBuffer.position(0);
float tempTexture[] = {
// Mapping coordinates for the vertices
0.0f, 1.0f, // top left (V2)
0.0f, 0.0f, // bottom left (V1)
1.0f, 1.0f, // top right (V4)
1.0f, 0.0f // bottom right (V3)
};
texture = new float[tempTexture.length];
System.arraycopy(tempTexture, 0, texture, 0, tempTexture.length);
byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
textureBuffer = byteBuffer.asFloatBuffer();
textureBuffer.put(texture);
textureBuffer.position(0);
}
/** The texture pointer */
private int[] textures = new int[1];
public void loadGLTexture(GL10 gl) { // every Sprite has to be loaded before being drawn
// generate one texture pointer
gl.glGenTextures(1, textures, 0);
// ...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
// create nearest filtered texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
// Use Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
}
public void draw(GL10 gl, float interpolation) {
gl.glPushMatrix();
gl.glTranslatef (speedInX * interpolation, speedInY * interpolation, 0f);
// bind the previously generated texture
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
// Point to our buffers
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// Set the face rotation
gl.glFrontFace(GL10.GL_CW);
// Point to our vertex buffer
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
// Draw the vertices as triangle strip
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
//Disable the client state before leaving
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glPopMatrix();
}
}
My renderer:
public class GlRenderer implements Renderer {
#Override
public void onDrawFrame(GL10 gl) {
// clear Screen and Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Reset the Modelview Matrix
gl.glLoadIdentity();
// Drawing
gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen
// is the same as moving the camera 5 units away
updateLogic(gl); //there was very much code around this but I removed it to make it more clear
float interpolation = (float) (SystemClock.uptimeMillis() + SKIP_TICKS - nextGameTick) / SKIP_TICKS;
spriteList.toFirst();
while (spriteList.getObject() != null) {
((Sprite) spriteList.getObject()).draw(gl, interpolation);
spriteList.next();
}
}
#Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION); // or some matrix uniform if using shaders
gl.glLoadIdentity();
gl.glOrthof(0, width, height, 0, -1, 1); // this will allow to pass vertices in 'canvas pixel' coordinates
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
#Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glDisable(GL10.GL_DITHER);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping ( NEW )
gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //Set Background
gl.glClearDepthf(1.0f); //Depth Buffer Setup
gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing
gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To Do
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); // So alpha works, but it still doesnt work everytime :)
spriteList.toFirst();
while (spriteList.getObject() != null) {
((Sprite) spriteList.getObject()).loadGLTexture(gl);
spriteList.next();
}
}
}
brecause you have
gl.glOrthof(0,width,height,0,-1,1);
your code doesnt require depth testing, try getting rid of
| GL10.GL_DEPTH_BUFFER_BIT
gl.glClearDepthf(1.0f);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glTranslatef(0.0f, 0.0f, -5.0f);

2D rendering with VBO in lwjgl won't draw

I'm working on a 2D game in LWJGL. I have successfully rendered QUADS with textures using glBegin but moving to VBOs turned out to be a big undertaking. At the moment I can switch between the vbo and non-vbo rendering with a boolean, both using the same vertex- and texture coordinates. The VBO-implementation won't draw anything onto the screen. Can anyone point me in the right direction?
This is my initialization:
public void init() {
VBOID = VBOHandler.createVBOID();
TBOID = VBOHandler.createVBOID();
float[] vdata = {0, 0,
width, 0,
width, height,
0, height};
float[] tdata = {sx, sy,
ex, sy,
ex, ey,
sx, ey};
//Texture coordinates: (0,0)(1,0)(1,1) and (0,1)
FloatBuffer fb = BufferUtils.createFloatBuffer(8);
fb.put(vdata);
VBOHandler.bufferData(VBOID, fb);
fb = BufferUtils.createFloatBuffer(8);
fb.put(tdata);
VBOHandler.bufferData(TBOID, fb);
}
And here is my rendering code:
private void render() {
texture.bind();
if(vbo) {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
VBOHandler.bindBuffer(VBOID);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
VBOHandler.bindBuffer(TBOID);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
VBOHandler.bindElementBuffer(VBOHandler.getDefaultIBOID());
// I figured why not use a standard IBO for all my sprite drawing
// The default IBO ID is initialized earlier in the program, not shown in this code
GL12.glDrawRangeElements(GL11.GL_TRIANGLE_FAN, 0, 3, 4, GL11.GL_UNSIGNED_SHORT, 0);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
} else {
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glTexCoord2f(sx, sy);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(ex, sy);
GL11.glVertex2f(width,0);
GL11.glTexCoord2f(ex, ey);
GL11.glVertex2f(width, height);
GL11.glTexCoord2f(sx, ey);
GL11.glVertex2f(0, height);
GL11.glEnd();
}
}
And the VBOHandler class, for those interested
public class VBOHandler {
private static int IBOID;
public static void initDefaultIBO() {
IBOID = createVBOID();
short[] indexdata = {0, 1, 2, 3};
ShortBuffer shortBuffer = BufferUtils.createShortBuffer(4);
shortBuffer.put(indexdata);
VBOHandler.bufferElementData(IBOID, shortBuffer);
}
public static int getDefaultIBOID() {
return IBOID;
}
public static int createVBOID() {
if(GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
return ARBVertexBufferObject.glGenBuffersARB();
}
return 0;
}
public static void bufferData(int id, FloatBuffer buffer) {
if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
}
public static void bufferElementData(int id, ShortBuffer buffer) {
if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
}
public static void bindBuffer(int id) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
}
public static void bindElementBuffer(int id) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, id);
}
}
The above render-function lies within my Sprite class. It is called by my GameView every frame as so:
public void renderGame() {
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
sprite.render();
}
The GameView is initialized with the following code:
Display.setDisplayMode(new DisplayMode(1024, 768));
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND); // enable alpha blending
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(x - width/2, x + width/2, y + height / 2, y - height / 2, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
You did not call 'flip' on the FloatBuffers before passing them to OpenGL. You need to call 'flip()' on FloatBuffers before you pass them to OpenGL, or it will not be able to read them. It is worth noting that you cannot read the FloatBuffers after you call 'flip()' yourself.

Categories