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.