Intellij Idea java ThiledMap slick当前线程中未找到OpenGL上下文

6ie5vjzr  于 2023-10-15  发布在  Java
关注(0)|答案(1)|浏览(119)

我想使用. tmx文件作为TiledMap
这是我的主要课程:

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:在当前线程中找不到OpenGL上下文。在org。lwjgl。opengl。GLContext。getCapabilities(GLContext.java:124)at org.lwjgl.opengl.GL11.glGetError(GL11.java:1377)at org. newdawn。滑头opengl。InternalTextureLoader。getTexture(InternalTextureLoader.java:226)at org. newdawn。滑头opengl。InternalTextureLoader。getTexture(InternalTextureLoader.java:171),位于org.newdawn.slick.Image。(Image.java:196)at org.newdawn.slick.tiled.TileSet.(TileSet.java:113)at org. newdawn。滑头平铺。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.公司。总部init(Main.java:18)at com.公司。总部main(Main.java:11)at sun.reflect.NativeMethodSubjector or Impl.invoke0(Native Method)at sun.反思。NativeMethods工具实现在sun上调用(NativeMethodsObjectorImpl.java:62)。反思。DelegatingMethods委托或实施在java中调用(DelegatingMethodsLogorImpl.java:43)。lang。反思。方法。在com上调用(Method.java:498)。intellij。RT.处决。应用。AppMain. main(AppMain.java:147)

9rnv2umw

9rnv2umw1#

您不能简单地在init方法中开始呈现。您应该覆盖render方法并在那里进行渲染。此时,OpenGL上下文应该已经由Slick2D初始化。

public void render(GameContainer arg0, Graphics arg1) throws SlickException

相关问题