如何创建自己的openGL上下文并将其绑定到GLCanvas? [英] How can I create my own openGL context and bind it to a GLCanvas?

查看:290
本文介绍了如何创建自己的openGL上下文并将其绑定到GLCanvas?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我精通Java

So when I got to grips with the java

paint(Graphics g){}

我继续创建自己的渲染方法的方法,但是我必须学习缓冲策略以及如何获取"图形

method I moved on to creating my own render methods but I had to learn about buffer strategies and how to 'get' Graphics

因此,现在我正在学习openGL,我必须掌握该方法:

So now I am learning openGL, I have got to grips with the method:

@Override
public void display(GLAutoDrawable arg0){}

现在我想创建自己的渲染方法,到目前为止,我一直在不断遇到一个例外:

and now I would like to create my own render methods, so far I have constantly run up against one exception:

线程"main"中的异常javax.media.opengl.GLException:没有OpenGL 此线程上的当前上下文

Exception in thread "main" javax.media.opengl.GLException: No OpenGL context current on this thread

问题:如果我想在

@Override
public void display(GLAutoDrawable arg0){}

方法,如何确保GLCanvas的glContext为当前"

method, how do I ensure the glContext of my GLCanvas is "current"

作为一个代码示例,当我仔细查看api并广泛使用google时,你们中的许多链接都非常友好,以至于我以前已经在这里找到了,我仍然在画一个空白... !我最接近的是它没有引发没有当前上下文"异常,但屏幕只是永久变黑了!

Preferably as a code example, as I Have looked through the api's and used google extensivly, many links you guys have already been so kind as to put here I have already found before and I am still drawing a blank... literally! Closest I've got was when it didn't throw a "no current context" exception but the screen just went black permenantly!

推荐答案

我在这里找到了讨论此问题的文档:

I found documentation discussing this issue here:

http://fivedots.coe.psu.ac .th/〜ad/jg2/ch15/index.html

在Linux/OpenJDK 6/JOGL 2下,GLContext.makeCurrent()/release()hack似乎对我有用,但是我们将看到...尤其是,始终使OpenGL上下文切换线程成为可能.会产生(太多?)开销.

The GLContext.makeCurrent()/release() hack seems to work for me under Linux/OpenJDK 6/JOGL 2, but we will see... in particular, making the OpenGL context switch thread all the time like that will incur (too much?) overhead.

然后有JOGL 2和LWJGL的工具包的NEWT,但是它们似乎是一个全新的蜡球,需要再见Swing. :(

Then there is NEWT of JOGL 2 and LWJGL's toolkit, but they seem to be a whole new ball of wax to handle, bye bye Swing. :(

这篇关于如何创建自己的openGL上下文并将其绑定到GLCanvas?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆