Ive tried a lot but dont find my error. Heres my Code:
public class Renderer {
public static final int WIDTH = 1080, HEIGHT = 720, FPS = 60;
public static void createDisplay()
{
try {
Display.setDisplayMode(new DisplayMode(WIDTH,HEIGHT));
Display.create();
Display.setVSyncEnabled(true);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// enable alpha blending
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0,0,WIDTH,HEIGHT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
public static void updateDisplay(){
Display.update();
Display.sync(FPS);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f,0.2f,0.2f,1.0f);
}
public static void destroyDisplay()
{
Display.destroy();
}
public static void renderDisplay(ArrayList<GameObject> render, Camera cam)
{
Color.white.bind();
for(GameObject obj: render)
{
obj.getTex().bind();
if(obj instanceof Player)
{
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(obj.getX()+WIDTH/2-cam.getX(), obj.getY()+HEIGHT/2-cam.getY());
glTexCoord2f(obj.getTex().getWidth(),0);
glVertex2f(obj.getX()+WIDTH/2+obj.getSizeX()-cam.getX(), obj.getY()+HEIGHT/2-cam.getY());
glTexCoord2f(obj.getTex().getWidth(),obj.getTex().getHeight());
glVertex2f(obj.getX()+WIDTH/2+obj.getSizeX()-cam.getX(), obj.getY()+HEIGHT/2+obj.getSizeY()-cam.getY());
glTexCoord2f(0,obj.getTex().getHeight());
glVertex2f(obj.getX()+WIDTH/2-cam.getX(), obj.getY()+HEIGHT/2+obj.getSizeY()-cam.getY());
glEnd();
}else{
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f((obj.getX()-cam.getX()), (obj.getY()-cam.getY()));
glTexCoord2f(1,0);
glVertex2f((obj.getX()-cam.getX())+obj.getSizeX(), (obj.getY()-cam.getY()));
glTexCoord2f(1,1);
glVertex2f((obj.getX()-cam.getX())+obj.getSizeX(), (obj.getY()-cam.getY())+obj.getSizeY());
glTexCoord2f(0,1);
glVertex2f((obj.getX()-cam.getX()), (obj.getY()-cam.getY())+obj.getSizeY());
glEnd();
}
obj.getTex().release();
}
}
There is no error the Texture is just not displayed. I use this method to load the images:
public static Texture getTex(String path)
{
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
return texture;
}
This is my main game loop:
public static Player player = new Player(0, 0, 0, 0, 20, 20, 2, null);
public static Camera cam = new Camera(0, 0);
static ArrayList<GameObject> toRender = new ArrayList<GameObject>();
public static void main(String[] args) {
Renderer.createDisplay();
toRender.add(new Wall(300, 300, 200, 100, IO.getTex("res/Terrain/Grass.png")));
toRender.add(player);
player.setTex(IO.getTex("res/Entities/Player/Player.png"));
while(!Display.isCloseRequested())
{
Renderer.updateDisplay();
Input.updateInput();
player.update();
Renderer.renderDisplay(toRender, cam);
}
Renderer.destroyDisplay();
System.exit(0);
}
Its just displayed a white quad instead of a textured one.
To render Texture load with slick on LWJGL quads you need to bind the texture before draw the quads
just try
texture.bind(); //texture = your Texture name
before
glBegin(GL_QUADS);
Related
So, how do I rotate a triangle by pressing Up, Down, Left or Right. I have a Keyboard class which can read keys and create events. But I don't know the function for rotating in LWJGL 3. I think I'm familiar with the classic gl.h way of rotating, but since LWJGL 3 is pretty new there aren't alot of information on this. Here is code for Display class and KeyboardHandler class.
Display
public class Driver implements Runnable{
private GLFWKeyCallback keyCallback;
private Thread thread = new Thread();
private boolean running = false;
public long window;
private static final int WIDTH = 600;
private static final int HEIGHT = WIDTH / 12 * 9;
public Driver(){
}
private synchronized void start(){
thread.start();
running = true;
}
private synchronized void stop(){
try {
thread.join();
running = false;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run(){
init();
while(running){
render();
update();
if(glfwWindowShouldClose(window) == GL_TRUE){
running = false;
keyCallback.release();
}
}
}
public void init() {
if(glfwInit() != GL_TRUE){
System.err.println("Failed to initilaize OpenGL");
}
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
window = glfwCreateWindow(WIDTH, HEIGHT, "Endless", NULL, NULL);
if(window == NULL){
System.err.println("Could not create window. ");
}
glfwSetKeyCallback(window, keyCallback = new KeyboardHandler());
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, 100, 100);
glfwMakeContextCurrent(window);
glfwShowWindow(window);
}
public void update() {
if(KeyboardHandler.isKeyDown(GLFW_KEY_LEFT)){
//event who'll start rotation
}
glfwPollEvents();
}
public void render() {
GLContext.createFromCurrent();
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-1.0f / 2, -1.0f / 2);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0f / 2, 1.0f / 2);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(1.0f / 2, -1.0f / 2);
glEnd();
//rotation of triangle
glfwSwapBuffers(window);
}
public static void main(String[] args) {
Driver game = new Driver();
game.start();
game.run();
}
}
And KeyboardHandler
public class KeyboardHandler extends GLFWKeyCallback{
private static boolean keys[] = new boolean[65536];
public void invoke(long window, int key, int scancode, int action, int mods)
{
keys[key] = action != GLFW_RELEASE;
}
public static boolean isKeyDown(int keycode){
return keys[keycode];
}
}
I guess the rotation itself should happen in render() while the keycallback who triggers it should be in update()
With the introduction of LWJGL 3, you must use shaders to rotate, scale, and transform your objects. You can find many resources on the internet that show you how to do this, one of them being the OpenGL programming WikiBook. Specifically, in tutorial four, which deals with rotating objects in modern OpenGL
I have this code:
public class Main {
private BoardHandler boardHandler;
Main() {
Display.setTitle(Cons.WINDOW_TITLE);
try {
Display.setDisplayMode(new DisplayMode(Cons.SCREEN_WIDTH, Cons.SCREEN_HEIGHT));
Display.create();
}
catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Cons.SCREEN_WIDTH, Cons.SCREEN_HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glClearColor(0, 0, 0, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
boardHandler = new BoardHandler();
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT);
Clock.update();
// game:
boardHandler.update();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void main(String[] args) {
new Main();
}
}
I load textures using this function:
public static Texture loadTexture(String path, String fileType) {
Texture tex = null;
InputStream in = ResourceLoader.getResourceAsStream(path);
try {
tex = TextureLoader.getTexture(fileType, in);
}
catch (IOException e) {
e.printStackTrace();
}
return tex;
}
I draw stuff with this function:
public static void drawTile(Texture tex, float x, float y, float radius) {
tex.bind();
glTranslated(x - radius / 2, y - radius / 2, 0);
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2d(0, 0);
glTexCoord2d(1, 0);
glVertex2d(radius, 0);
glTexCoord2d(1, 1);
glVertex2d(radius, radius);
glTexCoord2d(0, 1);
glVertex2d(0, radius);
glEnd();
glLoadIdentity();
}
I draw these images:
http://imgur.com/4IZO9CC,gmpPfMM,gF1EeBs,nrv6NRR,OwLgHoM,wfGvAvr,CVEagHD,6ij24M4,pheIjuI#0
And get this as a result:
http://imgur.com/pgExbTE,liEJ01d#0
The X'es are drawn the exact same way as all the other tiles, yet the X'es has these ugly white borders around them. Do note that these white borders are "inside" of the image I'm trying to draw. The blackness inside the white borders is the background showing through like how it's supposed to look.
What is the problem? Why are the white borders present when those parts are transparent in the image? Is there a solution to this?
This is my first attempt at using any 2D/3D engine to draw stuff, I'm just searching for a quick fix if possible.
I fixed it! It seems like openGL (or at least the way I set it up) does not like semi-transparent images for some reason. All I had to do in order for the white borders to disappear was to make every pixel in the image either fully transparent or fully opaque.
I have a problem loading my image. This is what I get: http://imgur.com/BZaubNz. The black spaces shouldn't be there. I don't know if there's something wrong with my image or my code. I've tried other images and some work just fine with this code, some don't.
import java.io.IOException;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
import org.newdawn.slick.Color;
import org.lwjgl.opengl.GL11;
public void init() {
try {
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("sprites/playButton.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void render() {
texture.bind();
Color.white.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(400-getWidth()/2,250);
GL11.glTexCoord2f(1,0);
GL11.glVertex2f(400+getWidth()/2,250);
GL11.glTexCoord2f(1,1);
GL11.glVertex2f(400+getWidth()/2,250+getHeight());
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(400-getWidth()/2,250+getHeight());
GL11.glEnd();
}
This is the main render function.
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.setInitialBackground(255, 255, 255);
Display.create();
Display.setVSyncEnabled(true);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// init OpenGL here
MainMenu mainMenu = new MainMenu();
mainMenu.init();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glClearColor(255.0f, 255.0f, 255.0f, 0.0f);
GL11.glClearDepth(1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0,0,800,600);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 600, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
while (!Display.isCloseRequested()) {
// render OpenGL here
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
mainMenu.render();
Display.update();
Display.sync(100);
}
The problem i am encountering is that i cannot get my texture to render in the correct proportions and for some reason the texture is also repeating itself with a space inbetween.
this is the texture im using(i am trzing to fill the screen with this texture):
When rendered it looks like this(red outline is the entire screen and texture is rendered with a 1 px border):
and here is the code:
package game;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Timer;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.TextureLoader;
public class WarZone {
private boolean done = false;
private String windowTitle = "War Zone";
private DisplayMode displayMode;
private Timer timer;
private float dt;
public static void main(String[] args) {
new WarZone().run(false);
}
public void run(boolean fullscreen) {
try {
init();
switchToOrtho();
while (!done) {
timer.tick();
update();
render();
Display.update();
}
cleanup();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private void update() {
// Exit if Escape is pressed or window is closed
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) || Display.isCloseRequested()) {
done = true;
return;
}
}
private boolean render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear the screen and the depth buffer
GL11.glLoadIdentity(); // Reset the current modelview matrix
int w = displayMode.getWidth();
int h = displayMode.getHeight();
GL11.glColor3f(1, 0, 0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2i(0, 0);
GL11.glVertex2i(w, 0);
GL11.glVertex2i(w, h);
GL11.glVertex2i(0, h);
GL11.glEnd();
//if(true)return false;
GL11.glColor3f(0, 1, 1);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2i(1, 1);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2i(w - 1, 1);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2i(w - 1, h - 1);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2i(1, h - 1);
GL11.glEnd();
return true; // Rendered correctly
}
public static void switchToOrtho() {
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
}
public static void switchToFrustum() {
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
private void init() throws Exception {
createWindow();
initGL();
load();
}
private void load() throws FileNotFoundException, IOException {
TextureLoader.getTexture("BMP", new FileInputStream("res/temp/Main_Menu_Play_Button.bmp"), true).getTextureID();
}
private void createWindow() throws Exception {
DisplayMode availibleDisplayModes[] = Display.getAvailableDisplayModes();
for (DisplayMode d:availibleDisplayModes) {
if (d.getWidth() == 640 && d.getHeight() == 480 && d.getBitsPerPixel() == 32) {
displayMode = d;
break;
}
}
Display.setDisplayMode(displayMode);
Display.setTitle(windowTitle);
Display.create();
}
private void initGL() {
GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable texture mapping
GL11.glShadeModel(GL11.GL_SMOOTH); // Enable smooth shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background
GL11.glClearDepth(1.0f); // Depth buffer setup
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables depth testing
GL11.glDepthFunc(GL11.GL_LEQUAL); // Type of depth testing
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select projection matrix
GL11.glLoadIdentity(); // Reset the projection matrix
// Calculate the aspect ratio of the window
GLU.gluPerspective(45.0f, (float)displayMode.getWidth() / (float)displayMode.getHeight(), 0.1f, 100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);// Select the modelview matrix
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);// Most precise perspective calculations
}
public void requestFinish() {
done = true;
}
private void cleanup() {
Display.destroy();
}
}
I would reallz appreciate it if someone could tell me what i had done wrong.
First, I don't know what TextureLoader or newdawn.slick.opengl are, so there is only limited information I can give about this.
However, it is very possible that your texture loading code does not know how to handle non-power-of-two textures. Which means it is likely padding the texture's size out to the nearest power of two.
More importantly is this:
GL11.glColor3f(0, 1, 1);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2i(1, 1);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2i(w - 1, 1);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2i(w - 1, h - 1);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2i(1, h - 1);
GL11.glEnd();
This will draw a screen-sized quad (assuming that w and h are screen sizes). This quad maps the entire area of the texture to this quad. OpenGL is only doing what you told it to do: take the texture and map it to the quad.
If you want to draw a texture with pixel accuracy (1:1 texel to pixel), then you need to provide a width and height to the vertex positions that is equal to the texture's size, not the screen size.
Also, you set the color to (0, 1, 1). The default texture environment will multiply the per-vertex color by the texel values fetched from the texture. So you should either set the color to white, or change the texture environment.
OpenGL Doesn't like textures that are not powers of two if I recall. Is your texture a power of 2 for both height and width?
http://www.gamedev.net/topic/466904-opengl-textures-only-power-of-two/
Okay, I'm using Java and JoGL. I'm trying to load and display a texture, but the texture isn't showing up at all. I'm not getting any errors at all, so I don't know what the problem could be.
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;
import com.sun.opengl.util.j2d.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.nio.*;
import javax.imageio.*;
import javax.swing.*;
public class chartest extends JFrame implements GLEventListener, KeyListener
{
private int texture;
public void display(GLAutoDrawable gLDrawable)
{
final GL gl = gLDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
gl.glBegin(GL.GL_QUADS); // Draw A Quad
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-12.0f, -19.0f, -15.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 12.0f, -19.0f, -15.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 12.0f, 19.0f, -15.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-12.0f, 19.0f, -15.0f);
gl.glEnd(); // Done Drawing The Quad
gl.glFlush();
}
public void displayChanged(GLAutoDrawable g, boolean b, boolean b2){}
public void init(GLAutoDrawable gLDrawable)
{
final GL gl = gLDrawable.getGL();
gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_FLAT);
gl.glEnable(GL.GL_TEXTURE_2D);
texture = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
URL url = this.getClass().getResource("test.png");
try
{
BufferedImage img = ImageIO.read(url);
makeRGBTexture(gl, new GLU(), img, GL.GL_TEXTURE_2D, false);
}
catch(Exception e)
{
e.printStackTrace();
}
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
}
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height)
{
final GL gl = gLDrawable.getGL();
final GLU glu = new GLU();
if (height <= 0) // avoid a divide by zero error!
height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
System.exit(0);
}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public static void main(String[] args) {
chartest c = new chartest();
GLCanvas canvas = new GLCanvas(new GLCapabilities());
canvas.addGLEventListener(c);
c.add(canvas);
c.setSize(640, 480);
canvas.addKeyListener(c);
c.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
c.setVisible(true);
canvas.requestFocus();
}
//-----------------------
private void makeRGBTexture(GL gl, GLU glu, BufferedImage img, int target, boolean mipmapped)
{
ByteBuffer dest = null;
switch (img.getType())
{
case BufferedImage.TYPE_3BYTE_BGR:
case BufferedImage.TYPE_CUSTOM:
{
System.out.println("Custom");
byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
dest = ByteBuffer.allocateDirect(99999);
dest.order(ByteOrder.nativeOrder());
dest.put(data, 0, data.length);
break;
}
case BufferedImage.TYPE_INT_RGB:
{
int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
dest = ByteBuffer.allocateDirect(data.length * BufferUtil.SIZEOF_INT);
dest.order(ByteOrder.nativeOrder());
dest.asIntBuffer().put(data, 0, data.length);
break;
}
default:
throw new RuntimeException("Unsupported image type " + img.getType());
}
if (mipmapped)
{
glu.gluBuild2DMipmaps(target, GL.GL_RGB8, img.getWidth(), img.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
}
else
{
gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
}
}
private int genTexture(GL gl)
{
final int[] tmp = new int[1];
gl.glGenTextures(1, tmp, 0);
return tmp[0];
}
}
I don't see that you check for any OpenGL-errors. JOGL provides an easy way to do this. Just place glDrawable.setGL(new DebugGL(glDrawable.getGL())); at the beginning of your init method.
If that doesn't help I would check the image data and texture variable if they are non-zero.
I managed to get a texture loaded by using com.sun.opengl.util.texture.Texture and the tutorial I found here.