【问题标题】:java ThiledMap slick No OpenGL context found in the current threadjava ThiledMap slick 在当前线程中找不到 OpenGL 上下文
【发布时间】:2017-11-23 11:41:02
【问题描述】:

我想使用 .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 错误:在当前线程中找不到 OpenGL 上下文。 java.lang.RuntimeException:在当前线程中找不到 OpenGL 上下文。 在 org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124) 在 org.lwjgl.opengl.GL11.glGetError(GL11.java:1377) 在 org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:226) 在 org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:171) 在 org.newdawn.slick.Image.(Image.java:196) 在 org.newdawn.slick.tiled.TileSet.(TileSet.java:113) 在 org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:447) 在 org.newdawn.slick.tiled.TiledMap.(TiledMap.java:90) 在 org.newdawn.slick.tiled.TiledMap.(TiledMap.java:77) 在 com.company.Main.init(Main.java:18) 在 com.company.Main.main(Main.java:11) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

【问题讨论】:

    标签: java opengl intellij-idea slick tiled


    【解决方案1】:

    您不能简单地在init 方法中开始渲染。您应该重写 render 方法并在那里进行渲染。那时,OpenGL 上下文应该已经被 Slick2D 初始化了。

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

    【讨论】:

      猜你喜欢
      • 2013-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多