No OpenGL context found in the current thread, how do I fix this error?
35820 просмотра
5 ответа
I'm working on a card game, and currently have a good foundation but I'm running into an error when I run it in eclipse. I'm also using slick 2d.
Here is the error from the console.
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.renderer.ImmediateModeOGLRenderer.glGetError(ImmediateModeOGLRenderer.java:387) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:337) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:275) at org.newdawn.slick.Image.(Image.java:270) at org.newdawn.slick.Image.(Image.java:244) at org.newdawn.slick.Image.(Image.java:232) at org.newdawn.slick.Image.(Image.java:198) at Cards.Card.(Card.java:18)
Code where I believe the source of the error to be occuring(Card class)
package Cards;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class Card
{
final int numCards = 52;
Image[] card = new Image [numCards];
Card (int c)
{
String fileLocation = new String ();
for (int i = 1 ; i <= 52 ; i++)
{
fileLocation = "res/cards/" + i + ".png";
try
{
card [i] = new Image (fileLocation); //line
}
catch (SlickException e)
{
e.printStackTrace ();
}
}
}
public Image getImage (int cardlocation)
{
return card [cardlocation];
}
}
Has anybody seen this kind of problem before? How can I solve it?
Автор: Hayden Holligan Источник Размещён: 13.11.2019 11:46Ответы (5)
11 плюса
This kind of error is common for LWJGL starters. The OpenGL context gets bound to a thread when it's been created. So you can only access this context from the same thread.
As it does not look that you're working with different threads there might be another cause. Slick2D seems to need a valid OpenGL context for its Image
class.
So my first try would be to initialize an OpenGL context before initializing your card images.
Автор: Neet Размещён: 15.01.2013 10:164 плюса
This happened to me once, and I couldn't figure out what to do until I realized I was calling the image loader before OpenGL had initialized. Make sure that you aren't defining any variables with an image loader in the constructor(or any other method called) before OpenGL inits(what I did).
Are you defining a Card
class before OpenGL is initialized?
Hope this helps.
Автор: FracturedRetina Размещён: 24.03.2013 02:284 плюса
In lwjgl 3.x and higher, you can try:
GLContext.createFromCurrent();
If you're using libgdx, there is also Gdx.app.postRunnable(...)
to post a Runnable
on the render thread.
2 плюса
Well, what I've found is that you need to init your Display before you set your OpenGL environment :)...
Автор: Ordiel Размещён: 16.07.2013 01:122 плюса
An old thread, but it might help someone. Depending on which LWJGL you're using, init your Display:
LWJGL 3 (uses GLFW):
if (!glfwInit()) {
throw new IllegalStateException("Can't init GLFW");
}
LWJGL 2:
try {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
} catch (LWJGLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
I, mostly, forget Display.create() :)
Автор: Alex Ureche Размещён: 10.05.2016 05:02Вопросы из категории :
- java В чем разница между int и Integer в Java и C #?
- java Как я могу определить IP моего маршрутизатора / шлюза в Java?
- java Каков наилучший способ проверки XML-файла по сравнению с XSD-файлом?
- java Как округлить результат целочисленного деления?
- java Преобразование списка <Integer> в список <String>
- opengl Использование мышиного прокрутки в GLUT
- opengl Простой 3D графический проект?
- opengl OpenGL, вращающий камеру вокруг точки
- opengl Многоголовая система отображения
- opengl центр поиска 2D-треугольника
- lwjgl Предложите простую математическую библиотеку Java для матричных операций для использования с OpenGL (lwjgl)
- lwjgl No OpenGL context found in the current thread, how do I fix this error?
- lwjgl getResourceAsStream () возвращает ноль в jar, но хорошо в затмении
- lwjgl Как заставить Java использовать миллиметры вместо пикселей?
- lwjgl Как рисовать прозрачные текстуры в LWJGL?
- slick2d Рисовать дугу назад?
- slick2d Slick2d использует сглаживание с анимацией / изображениями
- slick2d SLICK && LWJGL Мерцающая проблема
- slick2d Java | Slick2D | Столкновения системы сущностей / игровых объектов