2017-06-20 92 views
0

我想用.tmx文件作爲TiledMap類中的OpenGL上下文的Java ThiledMap光滑沒有在當前線程

這是我的主類:

package com.company; 

import org.newdawn.slick.SlickException; 
import org.newdawn.slick.tiled.TiledMap; 

public class Main { 

    private static TiledMap map; 
    public static void main(String[] args) { 
     try { 
      init(); 
     } 
     catch (SlickException e) { 
      e.printStackTrace(); 
     } 
    } 
    private static void init() throws SlickException { 
     map = new TiledMap("com/company/untitled.tmx"); 
     map.render(100,100); 
    } 
} 

我有後續的問題,當我編譯我在的IntelliJ程序:

Tue Jun 20 23:37:23 IRDT 2017 ERROR:No OpenGL context found in the current thread. 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:1377) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:226) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:171) at org.newdawn.slick.Image.(Image.java:196) at org.newdawn.slick.tiled.TileSet.(TileSet.java:113) at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:447) at org.newdawn.slick.tiled.TiledMap.(TiledMap.java:90) at org.newdawn.slick.tiled.TiledMap.(TiledMap.java:77) at com.company.Main.init(Main.java:18) at com.company.Main.main(Main.java:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

回答

0

你不能簡單地開始呈現在init方法。您應該覆蓋render方法並在那裏進行渲染。那時OpenGL上下文應該已經被Slick2D初始化了。

public void render(GameContainer arg0, Graphics arg1) throws SlickException 
相關問題