Java lwjgl and slick are not displaying my textures
NickName:user2727211 Ask DateTime:2013-08-29T06:47:42

Java lwjgl and slick are not displaying my textures

I have tried a lot of different things, but nothing worked so far. at first, the problem was that there was just a blank screen when the program was run. I finally got it to display a blank white square. My images are 128x128 and the other is 512x512.

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
import org.lwjgl.input.Mouse;
import java.util.Random;

public class TextureDemo
{
private static Texture wood;
Random random = new Random();

    public TextureDemo()
{
    initGL(640, 480, "SLICK TEXTURES");
loadTexture("mozilla");

int x = 100, y = 100, count = 0, width = 0, height = 0, counter = 10;

    while(true)
    {
        count++;
        if(count == counter)
        {
            x--; y--; width++; height++; counter += random.nextInt(50) + 1;
        }

                render(x, y, width, height);
        Display.update();
        Display.sync(60);

        if(Display.isCloseRequested())
        {
            wood.release();
            Display.destroy();
            System.exit(0);
        }
    }
}


private void initGL(int width, int height, String title)
{
    try
        {
        Display.setDisplayMode(new DisplayMode(width, height));
    Display.setTitle(title);
    Display.create();
    }
    catch(LWJGLException e)
    {
    e.printStackTrace();
    Display.destroy();
    System.exit(1);
    }

    GL11.glEnable(GL11.GL_TEXTURE);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, 0, height, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

}


public void loadTexture(String key)
{
    try
    {
        wood = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("./res/images/"+key+".png"));
    System.out.println("working." + wood.getTextureID());
    }
    catch(FileNotFoundException e)
    {
    e.printStackTrace();
    Display.destroy();
    System.exit(1);
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }   
}


public void render(int x, int y, int width, int height)
{

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    System.out.println("working." + wood.getTextureID());

            GL11.glBegin(GL11.GL_QUADS);

                GL11.glBindTexture(GL11.GL_TEXTURE_2D, wood.getTextureID());
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(x + wood.getImageWidth(), y);
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(x + wood.getImageWidth(), y + wood.getImageHeight());
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(x, y + wood.getImageHeight());

    GL11.glEnd();
    System.out.println(wood.getHeight()+ " " +wood.getWidth());


}

    public static void main (String[] args)
{
    new TextureDemo();
}


}

I just want to be able to see the png's i have in the program. Soany ideas why i'm getting white images? how important is the order of the initGL method?

Copyright Notice:Content Author:「user2727211」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18499531/java-lwjgl-and-slick-are-not-displaying-my-textures

Answers
Martijn Courteaux 2013-08-28T22:49:39

Not sure about it, but I think you had to glEnable(GL_TEXTURE_2D); in this old deprecated OpenGL style. (Instead of GL_TEXTURE)\n\nUpdate: I really think you should do glEnable(GL_TEXTURE_2D);. Try using a gray clear color. Maybe they just turned into black squares instead of whites.\nSlick has a function to bind the texture (I'm not sure what getTextureID returns).\n\nUpdate: Make sure you first glBindTexture and then glBegin.",


More about “Java lwjgl and slick are not displaying my textures” related questions

Java lwjgl and slick are not displaying my textures

I have tried a lot of different things, but nothing worked so far. at first, the problem was that there was just a blank screen when the program was run. I finally got it to display a blank white s...

Show Detail

LWJGL and Slick textures display as black...?

I use eclipse. so in my workspace, under my project, i create a new folder "res" with a subfolder "images" that have all my png's for use as textures. so here is the method im using for loading the

Show Detail

LWJGL Textures and Strings

Is it possible to load PNG Textures and draw Strings in LWJGL WITHOUT using the Slick Framework? Everytime I google "how to load png images in lwjgl" I get answers like this -> "hey just use the

Show Detail

Trouble with slick.util and lwjgl textures

So I've recently started making a simple 2-D java game using jlwgl and slick-util. I ran into a problem when trying to load in textures to place on my tiles. I am using slick util to try and load

Show Detail

Displaying text in lwjgl in java without using slick

I am trying to display some text in lwjgl in java but I dont want to use slick library, do you know if there is any other way to show some text in java using lwjgl ? If so, which external libraries I

Show Detail

LWJGL Slick Java OS X Natives

I'm trying to make a jar out of my game written with LWJGL and Slick. My technique is to extract the natives out of the jar into a temporary directory and then change the org.lwjgl.librarypath to the

Show Detail

Textures not binding in OpenGL (LWJGL/Slick-util)

I have a problem with what seems to be binding the textures to a shape. When I do so, I get a white shape of the correct dimensions, the color given to it by Color.white.bind(). GraphicsManager.ja...

Show Detail

LWJGL - loading sounds and fonts without slick

I'm writing Minecraft-like game. For loading Textures and fonts(currently there is no sound) I use slick. Slick is no longer developed and maven repository is unavaible. Is there any other library (

Show Detail

Java Slick2D & lwjgl

i try to write the boot screen to test the game. When I try to run this code, I have some errors. I was looking for some information on anything specific but not learned, besides, someone mentioned...

Show Detail

Fixing Incompatibility Between LWJGL 3 and Slick-Util

What I am trying to do is map a texture to an OpenGL model within LWJGL. I know that LWJGL 3 and slick-util sometimes work together and sometimes don't. In my case, it works a little and then tries...

Show Detail