Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My problem is that I get errors when I use

texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("TEXTURE PATH HERE"));

it gives me these errors:

Exception in thread "main" java.lang.RuntimeException: No OpenGL context found in the current thread.
    at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
    at org.lwjgl.opengl.GL11.glGetError(GL11.java:1277)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:226)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:184)
    at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
    at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
    at game.Map.Init(Map.java:34)
    at game.Game.start(Game.java:17)
    at game.Game.main(Game.java:63)

My code uses ImageIO, Buffered Image and image.getRGB(); But it also uses the Slick-Util library for loading textures to render.

The full code for the Map.java class is:

`
package game;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


import javax.imageio.ImageIO;

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;



public class Map {


    int mapSize=100;
    int[] Tiles = new int[mapSize+1];
    int Tile;

    public Texture texture;

    public void Init()
    {
        try {
            // load texture from PNG file
            texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Tiles/Grass.png"));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

     public void LoadMap()
        {


            File file= new File("res/map.png");
              BufferedImage image = null;
            try {
                image = ImageIO.read(file);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            for(int Y = 0;Y<image.getHeight();Y++){
                for(int X = 0;X<image.getWidth();X++){

              int clr=  image.getRGB(X,Y); 
              int  red   = (clr & 0x00ff0000) >> 16;
              int  green = (clr & 0x0000ff00) >> 8;
              int  blue  =  clr & 0x000000ff;
              if(red==0&&green==0&&blue==0){
                  Tiles[Tile]=0;
              }
              if(red==255&&green==0&&blue==0){
                  Tiles[Tile]=1;
              }
              if(red==0&&green==255&&blue==0){
                  Tiles[Tile]=2;
              }
              if(red==0&&green==0&&blue==255){
                  Tiles[Tile]=3;
              }
              Tile++;
            }
            }
            for(int i = 0;i<mapSize;i++)
            {
                System.out.println(Tiles[i]);
            }


        }
     public void RenderMap()
     {

     }

}
`

So all I want to know is how can I fix this error and draw the textures down in the

 void Render()
    {

    }

method.

Thanks, Griffin.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I hope this clarifies it for you. I've noticed you're importing lwjgl, I take it you want more functionality than what Slick 2D is offering? I would need to see your lwjgl construction to comment further...

In a normal Slick 2D setup with BasicGame, you would do something similar to this:

import java.io.IOException;
import org.newdawn.slick.*;
import org.newdawn.slick.opengl.*;

public class TextureTest extends BasicGame
{
    private Texture texture;
    private Image grass;

    public TextureTest()
    {
        super("Texture Load Test");
    }

    @Override
    public void init(GameContainer container) throws SlickException
    {
        try
        {
            // load texture from PNG file
            texture = TextureLoader.getTexture("PNG", getClass().getResourceAsStream("grass.png"));
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        grass = new Image(texture);     
    }

    @Override
    public void update(GameContainer container, int delta)
            throws SlickException
    {
    }

    @Override
    public void render(GameContainer container, Graphics g)
            throws SlickException
    {   
        grass.draw();
    }

    public static void main(String[] args) throws SlickException
    {
        TextureTest game = new TextureTest();
        AppGameContainer app = new AppGameContainer(game);
        app.setAlwaysRender(true);
        app.start();
    }
}
share|improve this answer
add comment

Are you trying to load images into OpenGL before you create an OpenGL context (as in, open the game window via Slick)? That's not going to work.

share|improve this answer
    
This is only one of the 3 classes a have in my game so far. The game is launched in the game class then the init(); and loadMap(); are called. –  griffy100 Feb 23 '13 at 11:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.