Show Posts
|
|
Pages: [1] 2
|
|
1
|
Java Game APIs & Engines / JOGL Development / Re: Sharing VBOs across a JOGL context
|
on: 2011-04-29 05:00:33
|
I have the following, which seems to almost work. I just create a vanilla QGLWidget with no parameters to the constructor and the following code. The problem is getting the GL3 object. The strange thing is in resizeGL I can call getGL3 without problems. But in paintGL calling it returns a javax.media.opengl.GLException: Not a GL3 implementation (NativeException) error. Not sure why. I've tried calling makeCurrent on the Qt context, but then resizeGL gives the same error. I've confirmed that GLProfile.get(...) returns a GL3 profile, but the createExternalGLContext function returns a GL2 implementation. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| def initializeGL @glContext = GLDrawableFactory.getFactory(GLProfile.get(GLProfile::GL3)).createExternalGLContext() end
def resizeGL(width,height) @glContext.makeCurrent() gl = @glContext.getGL.getGL3 gl.glViewport(0,0,width,height) end
def paintGL @glContext.makeCurrent()
@gl = @glContext.getGL.getGL3 ... |
1 2 3 4 5 6 7 8
| [info] com.sun.opengl.impl.x11.glx.X11ExternalGLXContext [com.sun.opengl.impl.gl2.GL2Impl@1f01b29, [info] Drawable: com.sun.opengl.impl.x11.glx.X11ExternalGLXContext$Drawable[realized true, [info] factory com.sun.opengl.impl.x11.glx.X11GLXDrawableFactory@7dedad, [info] window NullWindow[config X11GLXGraphicsConfiguration[class javax.media.nativewindow.x11.X11GraphicsScreen[class javax.media.nativewindow.x11.X11GraphicsDevice[type X11, handle 0x780804f0], idx 0], visualID 0x21, fbConfigID 0x75, [info] requested GLCapabilities[Capabilities[Onscreen: true, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL2/GL2], PBuffer: true, DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false], [info] chosen GLCapabilities[Capabilities[Onscreen: true, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL2/GL2], PBuffer: true, DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false]], displayHandle 0x780804f0, surfaceHandle 0x4c00018, size 0x0], [info] requested GLCapabilities[Capabilities[Onscreen: true, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL2/GL2], PBuffer: true, DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false], [info] chosen GLCapabilities[Capabilities[Onscreen: true, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL2/GL2], PBuffer: true, DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false]]] |
|
|
|
|
|
2
|
Java Game APIs & Engines / JOGL Development / Re: Sharing VBOs across a JOGL context
|
on: 2011-04-28 19:02:46
|
|
I'm a little out of my element, too. I've been using a pBuffer because that's the only way I've ever been able to create a GL3-profiled context. And from what I understand the QGLContext and GLContext are two different things, where GLContext is from JOGL and can provide a valid "GL" object for running commands. Maybe I can try going without GL3 for a bit and doing everything through Qt. Then I can try GLContext.getCurrent() to see if JOGL can figure out the context can give me a JOGL context to get the GL object from.
|
|
|
|
|
3
|
Java Game APIs & Engines / JOGL Development / Re: Sharing VBOs across a JOGL context
|
on: 2011-04-28 17:30:11
|
I changed the code around so it's only making one QGLWidget at startup, which seems to work fine. However, when creating a new QGLWidget after launching, I still don't see anything drawn in that widget. I guess I could call "isSharing" on the secondary widgets to see if they really are sharing. I'm using jruby so I'm wondering if when I call the super constructor, it's really sending @@firstPanel to the correct function or sending it to the wrong constructor and just not displaying any errors and not sharing. I might do this part in java or scala just to make sure. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| class PanelGL < QGLWidget @@firstPanel = nil @@pBuffer = nil def initialize(parent = nil) if @@firstPanel super(parent, @@firstPanel) else super
profile = GLProfile.get(GLProfile::GL3) glCaps = GLCapabilities.new(profile) glCaps.setPBuffer true if not @@pBuffer @@pBuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(glCaps, DefaultGLCapabilitiesChooser.new(), 1, 1, nil) end @@firstPanel = this end end
def initializeGL @ctx = @@pBuffer.getContext() end attr_reader :gl
def resizeGL(width,height) @ctx.makeCurrent() gl = @ctx.getGL.getGL3 gl.glViewport(0,0,width,height) end
def paintGL @ctx.makeCurrent() @gl = @@pBuffer.getContext().getGL.getGL3 ... |
|
|
|
|
|
4
|
Java Game APIs & Engines / JOGL Development / Re: Sharing VBOs across a JOGL context
|
on: 2011-04-28 04:41:36
|
|
I've seen the sharewith property before, but I'm not sure how to properly use it. When I create the first one, do I still need to create pbuffer object or do I need to do something else? I've spent hours looking for context-sharing in QGLWidgets, but the only posts I've found are just similar ones I've created earlier. I might remember some site long ago saying I had to create my first widget and update it because it wouldn't have a context to share later until I drew it. Is that really required, because that seems like a massive headache, and documentation is very old for JOGL.
I just want a simple example to create multiple QGLWidgets that share the same GL3 context.
Thanks.
|
|
|
|
|
5
|
Java Game APIs & Engines / JOGL Development / Sharing VBOs across a JOGL context
|
on: 2011-04-27 18:07:54
|
I'm trying to get VBOs shared across multiple QGLWidgets. I'm using JOGL and jruby and noticed when I switched to VBOs from immediate mode, I no longer have any meshes drawing in the secondary windows. I'm sharing the VBOs in a global variable. I understood that I just had to create a pbuffer and share the contexts between multiple GLWidgets. That doesn't seem to be the case, however. Maybe I'm not setting up my VBO correctly or there's another step to setup the context? Or an explicit sharing function? 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class PanelGL < QGLWidget @@pBuffer = nil def initialize(parent = nil) super setMouseTracking(true) profile = GLProfile.get(GLProfile::GL3) glCaps = GLCapabilities.new(profile) glCaps.setPBuffer true if not @@pBuffer @@pBuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(glCaps, DefaultGLCapabilitiesChooser.new(), 1, 1, nil) end end |
You can see the code in it's entirety here with the important stuff starting around line 750. http://code.google.com/p/sunshine/source/browse/src/main/resources/com/googlecode/sunshine/clear_scene.rb?r=9a2872d17b51
|
|
|
|
|
7
|
Java Game APIs & Engines / JOGL Development / Re: creating a GL3 object in QtJambi
|
on: 2010-10-09 17:05:19
|
Adding GLContext.getCurrentGL().getGL3() at the end of my initializeGL function returns an error saying there's not context current 1
| Exception in thread "main" javax/media/opengl/GLContext.java:159:in `getCurrentGL': javax.media.opengl.GLException: No OpenGL context current on this thread (NativeException) |
1 2 3 4 5 6 7 8 9
| public void initializeGL() { profile = GLProfile.get(GLProfile.GL3) glCaps = GLCapabilities.new(profile) glCaps.setPBuffer(true) factory = GLDrawableFactory.getFactory(profile) ctx = factory.createExternalGLContext() gl = GLContext.getCurrentGL().getGL3() } |
|
|
|
|
|
9
|
Java Game APIs & Engines / JOGL Development / creating a GL3 object in QtJambi
|
on: 2010-10-08 05:42:04
|
I'm having some difficulty getting a GL3 context now that I've switched to QtJambi. When casting my gl object to GL using getGL3, it throws the error "javax.media.opengl.GLException: Not a GL3 implementation". This is my original code when I was using swing... GLProfile profile = GLProfile.get(GLProfile.GL3) GLCapabilities glCaps = new GLCapabilities(profile) glCaps.setPBuffer(true) GLPBuffer pbuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(glCaps, new DefaultGLCapabilitiesChooser(), 1, 1, null) canvas = new GLCanvas(glCaps, new DefaultGLCapabilitiesChooser(), PanelGL.pbuffer.getContext(), null) Switch to QtJambi, I have the following code: GLProfile profile = GLProfile.get(GLProfile::GL3) GLCapabilities glCaps = GLCapabilities.new(profile) glCaps.setPBuffer(true) factory = GLDrawableFactory.getFactory(profile) ctx = factory.createExternalGLContext gl = ctx.getGL.getGL3 This last line throws an error. I've seen this page ( http://www.java-gaming.org/index.php?action=printpage;topic=21064.0), which solves the issue, but it's passing something to a GLCanvas constructor, which is swing. Is there an equivalent setup in QtJambi to get me a GL3 object?
|
|
|
|
|
10
|
Java Game APIs & Engines / JOGL Development / Re: sharing a GLContext across several GLCanvas and JPanel instances
|
on: 2010-08-14 16:04:34
|
It worked! You are all beautiful people. The main two differences I can see are calling setPBuffer(...) on the GLCapabilities I pass to the pbuffer, and making a separate GLCapabilities object for the GLCanvas's than I use for the pbuffer itself. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| object PanelGL { val profile = GLProfile.get(GLProfile.GL3) val glCaps = new GLCapabilities(profile) glCaps.setPBuffer(true) val pbuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(glCaps, new DefaultGLCapabilitiesChooser(), 1, 1, null)
} class PanelGL extends JPanel with GLEventListener with MouseListener with MouseMotionListener { setLayout(new BorderLayout()) setMinimumSize(new Dimension(200,200)) setPreferredSize(new Dimension(800,600))
var glCaps = new GLCapabilities(PanelGL.profile) val canvas = new GLCanvas(glCaps, new DefaultGLCapabilitiesChooser(), PanelGL.pbuffer.getContext(), null) add(BorderLayout.CENTER, canvas) canvas.addGLEventListener(this) canvas.addMouseListener(this) canvas.addMouseMotionListener(this) |
|
|
|
|
|
11
|
Java Game APIs & Engines / JOGL Development / Re: sharing a GLContext across several GLCanvas and JPanel instances
|
on: 2010-08-13 06:26:58
|
Maybe if I made a simpler example. If the JPanel below were to be a GLEventListener with a GLCanas inside it, how would one set it up so all instances shared the same context as a pbuffer? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import javax.swing.*; import java.awt.*;
public class Test extends JPanel { public static void main(String[] args) { Test test = new Test();
JFrame frame = new JFrame("test"); JTabbedPane pane = new JTabbedPane(); pane.addTab("Tab 1", new Test()); pane.addTab("Tab 2", new Test()); pane.addTab("Tab 3", new Test()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(pane); frame.setSize(800,600); frame.setVisible(true); }
JTabbedPane tabbedPane;
Test() { } } |
|
|
|
|
|
12
|
Java Game APIs & Engines / JOGL Development / Re: sharing a GLContext across several GLCanvas and JPanel instances
|
on: 2010-08-11 03:27:57
|
Between creating a pBuffer and sharing the first context created, are there advantages and disadvantages to each one? Here's my code in scala. I'm probably doing something naive. removeNotify never seems to be called switching panels. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| object PanelGL { var context = null : GLContext var capabilities = null : GLCapabilities var profile = null : GLProfile def getContext():GLContext = { if (context == null) { val capabilities = getCapabilities() capabilities.setDepthBits(24) val pBuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(capabilities, new DefaultGLCapabilitiesChooser, 1, 1, null) context = pBuffer.getContext() } context } def getCapabilities():GLCapabilities = { if (profile == null) profile = GLProfile.get(GLProfile.GL3); if (capabilities == null) capabilities = new GLCapabilities(profile) capabilities } def instance:PanelGL = { val singlePanel = new PanelGL() Copper.glPanels += singlePanel singlePanel } } class PanelGL extends JPanel with GLEventListener with MouseListener with MouseMotionListener { setLayout(new BorderLayout()) setMinimumSize(new Dimension(200,200)) setPreferredSize(new Dimension(800,600))
var canvas = null : GLCanvas override def setVisible(aFlag:boolean) { super.setVisible(aFlag)
if (canvas == null) { canvas = new GLCanvas(PanelGL.getCapabilities(), new DefaultGLCapabilitiesChooser, PanelGL.getContext(), null) add(BorderLayout.CENTER, canvas) }
canvas.addGLEventListener(this) }
override def addNotify() { super.addNotify() println("addNotify") }
override def removeNotify() { super.removeNotify() println("removeNotify") } |
I just barely found this and was going to start scanning through it to see how it implements the context sharing. http://www.koders.com/java/fidDAD2B2DC72C134C327CCD667898FC9BE0F185930.aspx
|
|
|
|
|
13
|
Java Game APIs & Engines / JOGL Development / Re: sharing a GLContext across several GLCanvas and JPanel instances
|
on: 2010-08-10 15:20:02
|
1. Make sure your first GLCanvas is visible before you use it to create the other GLCanvas's, because it might not have set its GLContext up correctly until it is added to a visible component (that's a maybe, most times GLCanvas is pretty good about having a context right away).
I tried that with limited success. I overrode the setVisible function and added the GLCanvas then. I store it's context and try using it when the other two pop up. I get an image on the first panel but nothing at all on the second two panels. Would I have more success using GLJPanel? 2. Check the behavior of the tab widget to see if switching tabs indirectly calls addNotify() and removeNotify() on the GLCanvas's. You can do this by extending the GLCanvas class, overriding those two methods to print out statements and then call super.XNotify().
What exactly am I checking for? 3. Use a GLPBuffer as the shared context. You create a 1x1 context in the beginning of your code and all GLCanvases share with it.
Doing this, I got a ton of stuff dumped to the screen, but didn't get an image in any of the GLCanvas's that tried to use the context. 1 2 3 4 5 6 7 8 9 10 11 12
| [java] Desired: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 0, Green Accum: 0, Blue Accum: 0, Alpha Accum: 0, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 0: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 1: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 8, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 2: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 3: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 8, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 4: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 5: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 8, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 6: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 0, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 7: GLCapabilities[Capabilities[Onscreen: false, Red: 8, Green: 8, Blue: 8, Alpha: 8, Opaque: true], GL profile: GLProfile[GL3/GL3], PBuffer: true, DoubleBuffered: false, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 8, Red Accum: 16, Green Accum: 16, Blue Accum: 16, Alpha Accum: 16, Multisample: false, Num samples: 0, PBuffer-FloatingPointBuffers: false, PBuffer-RenderToTexture: false, PBuffer-RenderToTextureRectangle: false] [java] Available 8: GLCapabilities[Capabi ...
etc. |
|
|
|
|
|
14
|
Java Game APIs & Engines / JOGL Development / [SOLVED] sharing a GLContext across several GLCanvas and JPanel instances
|
on: 2010-08-08 02:45:59
|
I have small app that have a tab widget holding several JPanels, each holding a GLCanvas. After getting a VBO setup and working in one, I found my app would crash (SIGSEGV) if I moved from tab to another. I figured this had something to do with trying to share the VBO and/or shaders across contexts. To solve the problem, I figured I would change the way I create the GLCanvas, by sending it a context from a previous GLCanvas if it already exists. 1 2 3 4 5 6 7 8 9 10 11 12 13
| capabilities = new GLCapabilities(profile)
if (PanelGL.context == null) { canvas = new GLCanvas(capabilities) PanelGL.context = canvas.getContext() } else { new GLCanvas(capabilities, new DefaultGLCapabilitiesChooser(), PanelGL.context, null) } |
This fixed the error, but now on the second and third GLCanvases their screens are completely green. The green makes sense as right now I just have it hard-coded into the fragment shader, but on the first screen while I see the bunny model, on the second and third it's just green. I don't know if it's a bug in my setup or if the camera is just too close to the model (although I'm guessing it's more my setup). As I am running Linux, I have tried adding the "-Djogl.GLContext.optimize" as recommended in the JOGL User Guide, but that just made my program exit instead of getting the green screen. Is this the correct way to share a context across multiple CLCanvas instances? Do I need to do anything different with the VBO and shaders to share them as well?
|
|
|
|
|
16
|
Java Game APIs & Engines / JOGL Development / Re: VBO error: array vertex_buffer_object must be disabled
|
on: 2010-08-05 07:07:09
|
Alright, I cleaned up my code to look like Stu Pomerantz's VBO example ( http://stupomerantz.com/public/opengl/). It certainly looks cleaner, but I'm still not getting anything drawn to my screen. I still need to check the output of my shaders to make sure they're working, but still I'm perplexed why nothing is showing up. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| val bufferObject = new Array[int](1) def init(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3()
gl.glClearColor(.3f, .3f, .3f, 0)
val triangleData = BufferUtil.newFloatBuffer(9) triangleData.put(-0.9f) triangleData.put(-0.9f) triangleData.put(-1f)
triangleData.put(0.9f) triangleData.put(-0.9f) triangleData.put(-1f)
triangleData.put(0.9f) triangleData.put(0.9f) triangleData.put(-1f)
gl.glGenBuffers(1, bufferObject, 0) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) gl.glBufferData(GL.GL_ARRAY_BUFFER, 9*BufferUtil.SIZEOF_FLOAT, triangleData, GL.GL_STATIC_DRAW) } |
1 2 3 4 5 6 7 8 9 10 11 12 13
| def display(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3() gl.glClear(GL.GL_COLOR_BUFFER_BIT)
dummyShader.bind(gl) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) val vertexLocation = dummyShader.attribLocation(gl, "vertex") gl.glVertexAttribPointer(vertexLocation, 3, GL.GL_FLOAT, false, 0, 0) gl.glEnableVertexAttribArray(vertexLocation) gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3) dummyShader.release(gl) } |
1 2 3 4 5
| in vec3 vertex;
void main() { gl_Position = vec4(vertex,1.0); } |
1 2 3
| void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); } |
|
|
|
|
|
18
|
Java Game APIs & Engines / JOGL Development / Re: VBO error: array vertex_buffer_object must be disabled
|
on: 2010-08-04 15:11:30
|
When in trouble, simplify your problem. Don't debug something in the middle of a complex app. This is easier said than done with OpenGL 3, and I wouldn't call this a complex app. One has to go through a bit of code just to get something on the screen. I couldn't find many JOGL VBO examples, so I grabbed a C++ one, which was apparently wrong. I'm going to try getting it to work with JOGL 2.0 (was using 1.1.1). Based on some other example code, I have the following so far. It's in scala, but should be easy enough to read. Do you see anything wrong with this? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| def display(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3() gl.glClear(GL.GL_COLOR_BUFFER_BIT) gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4) }
val gl = drawable.getGL().getGL3()
gl.glGenBuffers(1, bufferObject, 0) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) gl.glBufferData(GL.GL_ARRAY_BUFFER, 4 * 2 * BufferUtil.SIZEOF_FLOAT, buffer, GL.GL_STATIC_DRAW) val data = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY).asFloatBuffer() data.put(-0.75f) data.put(-0.75f) data.put(-0.75f) data.put(0.75f) data.put(0.75f) data.put(0.75f) data.put(0.75f) data.put(-0.75f) gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER)
gl.glVertexAttribPointer(0, 2, GL.GL_FLOAT, false, 0, 0) val vs = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER) gl.glShaderSource(vs, 1, (const GLchar **) &vertex_shader_code, NULL) gl.glCompileShader(vs) val fs = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER) gl.glShaderSource(fs, 1, (const GLchar **) &fragment_shader_code, NULL) gl.glCompileShader(fs) val program = gl.glCreateProgram() gl.glAttachShader(program, vs) gl.glAttachShader(program, fs) gl.glLinkProgram(program) gl.glUseProgram(program) } |
Also, you can see I use GL2ES2 to get the vertex and fragment values. For some reason GL.GL_VERTEX_SHADER and GL.GL_FRAGMENT_SHADER weren't contained in GL or GL3 despite what the documentation said.
|
|
|
|
|
19
|
Java Game APIs & Engines / JOGL Development / [SOLVED] VBO error: array vertex_buffer_object must be disabled
|
on: 2010-08-04 05:47:50
|
I keep getting this error trying to get a basic VBO to work. Is this a common error? 1
| Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: array vertex_buffer_object must be disabled to call this method |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| gl.glGenBuffersARB(1, vertexVBO, 0) gl.glGenBuffersARB(1, indexVBO, 0)
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vertexVBO(0)) gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, triangleCount * 3 * 3 * BufferUtil.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW_ARB) gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, indexVBO(0)) gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, triangleCount * 3 * BufferUtil.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW_ARB)
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices)
... fill in with data ...
gl.glEnableClientState(GL.GL_VERTEX_ARRAY) gl.glDrawElements(GL.GL_TRIANGLES, triangleCount, GL.GL_UNSIGNED_SHORT, 0) gl.glDisableClientState(GL.GL_VERTEX_ARRAY)
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, 0) gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, 0) |
|
|
|
|
|
20
|
Java Game APIs & Engines / JOGL Development / solving packaging issues once and for all
|
on: 2010-02-27 00:11:20
|
|
I usually use ant for my little applications and it usually takes me a little bit to organize it to include the system files JOGL requires. My end goal is to be able to get the entire package into a single jar file per OS (project_windows.jar, project_linux.jar, etc.). I've started using jarjar, which seems fine for including non-system-based libraries into the final jar file, but it doesn't handle the dynamic libraries. I'm told I need to actually move the so's and dll's to a new directory outside of a jar for the JVM to read them, but that's been a headache. I've been trying to search through the jar at runtime to find the so's and dll's and copy them to a temp dir, but it's not working somewhere. Is there a different way to go about this? Is there some generic one-size-fits-all JOGL jar file I link to on the internet? I just want everything into one little jar file and be callable without modifying the classpath manually...
java -jar project_windows.jar
|
|
|
|
|
21
|
Java Game APIs & Engines / JOGL Development / gl_FragColor multiplied against gl_Color for no reason
|
on: 2010-02-05 15:41:03
|
I'm trying get my GLSL shader working, but I have a really funky error I don't think I've ever seen. This may be a JOGL bug, but I assume it's a user error somehow. My Java code... 1 2 3 4 5 6 7 8
| println(gl.glIsEnabled(GL.GL_BLEND)) shader.bind(gl) gl.glColor3f(1f,0f,0f) gl.glColor3f(0,0,0) gl.glBegin(GL.GL_QUADS) ... gl.glEnd() shader.release() |
vertex shader... 1 2 3 4
| void main() { gl_Position = ftransform(); } |
fragment shader... 1 2 3
| void main() { gl_FragColor = vec4(0.8, 0.2, 0.2, 1.0); } |
I know the vertex shader is working because I can alter it's final output location changing on my screen. With the fragment shader, something funky is going on. I would expect with no blending to get a red on my screen, but what I get actually depends on glColor3f. If I put in glColor3f(0,0,0), I get black as if I have no shader. If I put in glColor3f(1,1,1), I get the color (.8,.2,.2) from my shader. I can adjust the values of glColor3f to adjust the output color, so it appears to my that glColor3f color is being multiplied by the final color in GLSL. To my knowledge, only blending would create a color different that the color from the gl_FragColor, but blending isn't enabled. Am I crazy? Is there a bug in my code? Could it be a JOGL issue? This is a duplicate of this thread, but I wanted to present it on this forum just in case it was indeed a JOGL issue. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=271564&#Post271564
|
|
|
|
|
22
|
Java Game APIs & Engines / JOGL Development / Re: problem with mouse listener on GLCanvas/GLJPanel in Netbeans RCP
|
on: 2009-03-24 21:09:36
|
Can I ask why you have two mouse listeners on the same panel? Two mouse listeners? I see one mouse listener. And I see one GLEventListener. Just like having one mouse listener and one mouse-motion listener. They handle different kinds of events. GLEventListener methods are called when the GLCanvas needs to be redrawn. So I will probably in the end have a MouseListener, MouseMotionListener, KeyListener, and GLEventListener to respectively handle mouse clicks, mouse drags, key presses, and screen redraws. Make sense?
|
|
|
|
|
23
|
Java Game APIs & Engines / JOGL Development / Re: problem with mouse listener on GLCanvas/GLJPanel in Netbeans RCP
|
on: 2009-03-24 19:20:21
|
well on second read here, because you have an abstract class with your mouseListener methods in it, still means you have to put the methods for them in your main-class(the class you need listening in). If you already did that then I am misunderstanding what you just last said. The class isn't abstract, the methods it has to implement inheriting from MouseListener are. Because it isn't an abstract class, it has to implement the mouse listener methods. The situation is I implement my class to as a GLEventListener and a MouseListener. I add my class to the GLCanvas twice. Only one listener works and not the other even though I set them up the same as I always have. Here's an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class MyTopComponent extends TopComponent implements GLEventListener, MouseListener { public MyTopComponent() { initComponents(); canvas.addGLEventListener(this); canvas.addMouseListener(this); }
public void mousePressed(MouseEvent event) { System.out.println("This message is never seen"); } .... other mouse methods
public void display(GLAutoDrawable drawable) { System.out.println("This message is seen and I can draw stuff"); ... } .... other gl methods } |
|
|
|
|
|
25
|
Java Game APIs & Engines / JOGL Development / Re: problem with mouse listener on GLCanvas/GLJPanel in Netbeans RCP
|
on: 2009-03-24 16:58:29
|
It's fairly simple. Add the TopComponent to the GLCanvas mouse list, and mousePressed gets called. This is what it's supposed to do. If it worked fine, I wouldn't have typed the part about not getting any mouse events. It's a simple idea that's not working and I'm not sure how to debug it because it's simple. It's clear I add the mouse listener to the the canvas, but I don't get any mouse events when I click on it. That's my problem.
|
|
|
|
|
26
|
Java Game APIs & Engines / JOGL Development / problem with mouse listener on GLCanvas/GLJPanel in Netbeans RCP
|
on: 2009-03-24 16:51:18
|
I have a TopComponent (from Netbeans RCP) with a GLCanvas (tried GLJPanel, too) sitting in it. In my constructor I have these two lines 1 2 3 4 5
| { ... glCanvas.addGLEventListener(this); glCanvas.addMouseListener(this); } |
The GLEvent handling functions are being called appropriately, but I can't get any mouse events at all. mousePressed is never entered. I'm not sure if this is related to Netbeans RCP modules--I'm told by others it's not--but I've never had this situation happen. It's fairly simple. Add the TopComponent to the GLCanvas mouse list, and mousePressed gets called. I've done it successfully in a normal Java app using JOGL. Does Netbeans RCP do anything funky to catch these mouse events?
|
|
|
|
|
27
|
Java Game APIs & Engines / JOGL Development / text rendering bug using two QGLWidgets in QtJambi
|
on: 2009-01-30 06:06:29
|
I am making two QGLWidgets that are identical at launch, but the second sometimes has garbled text. It's always the second window and only half the time. 1 2
| QFont font = new QFont("Arial", 16); renderText(x, y, string, font); |
I've tried making the font initialized only once per render loop or sharing it across the two widgets, but that hasn't solved the issue. Has anyone seen this and know of a way to fix it? I've included a screenshot. Thanks.
|
|
|
|
|
28
|
Java Game APIs & Engines / JOGL Development / javax.media.opengl.GLException: Context not current
|
on: 2008-12-18 15:00:15
|
I'm playing around with QtJambi. For some reason I receive a 1
| javax.media.opengl.GLException: Context not current |
when I call glTexImage2D. It doesn't seem to complain when I call glGenTexture and seems to give me a valid handle. I found a similar issue <a href=' http://markmail.org/message/tryzpw747yuja32m#query:"javax.media.opengl.GLException%3A Context not current"+page:1+mid:tryzpw747yuja32m+state:results'>here</a> but he/she never got a response. Also, that was back in 2006 so if it was a bug, I would it is resolved by now. Has anyone experienced this exception? I make a texture handle right before it and do some GL drawing right after it (if I comment it out).
|
|
|
|
|
29
|
Java Game APIs & Engines / JOGL Development / shaders in a JOGL applet
|
on: 2008-11-02 14:36:20
|
I'm playing around with a JOGL applet. Everything seems to be working well, but adding shaders causes a GL_INVALID_OPERATION after glUseProgram. I'm using the "hello world" style shaders, so they seem to be too simple to cause problems. I seem to be getting a 4 for the glsl program, which seems high since there is only one, but I don't think that should be an issue either. Can anyone spot the problem with my code or give me a reason why shaders don't work in JOGL applets? Binding my shader class gives me this trace: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Exception in thread "AWT-EventQueue-2" javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glUseProgram(): GL_INVALID_OPERATION at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:12715) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9774) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9773) at base.shader.ShaderProgram.bind(ShaderProgram.java:71) ... |
I've even tried not attaching either shader to the program. Here's my shader code that handles the setup: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import javax.media.opengl.DebugGL; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable;
public abstract class ShaderProgram { public void validate(GLAutoDrawable drawable) { drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); int v = gl.glCreateShader(GL.GL_VERTEX_SHADER); int f = gl.glCreateShader(GL.GL_FRAGMENT_SHADER); String line;
try { BufferedReader brv = new BufferedReader(new InputStreamReader(vert_url.openStream())); String[] vsrc = new String[1]; while ((line=brv.readLine()) != null) { System.out.println(line); vsrc[0] += line + "\n"; } gl.glShaderSource(v, 1, vsrc, (int[])null, 0); gl.glCompileShader(v); } catch (FileNotFoundException e) { System.err.println("File not found: " + e.getMessage()); } catch (IOException e) { System.err.println("IO error: " + e.getMessage()); } try { BufferedReader brf = new BufferedReader(new InputStreamReader(frag_url.openStream())); String[] fsrc = new String[1]; while ((line=brf.readLine()) != null) { fsrc[0] += line + "\n"; System.out.println(line); } gl.glShaderSource(f, 1, fsrc, (int[])null, 0); gl.glCompileShader(f); } catch (FileNotFoundException e) { System.err.println("File not found: " + e.getMessage()); } catch (IOException e) { System.err.println("IO error: " + e.getMessage()); }
program = gl.glCreateProgram(); program = gl.glCreateProgram(); gl.glLinkProgram(program); gl.glValidateProgram(program); valid = true; } public void bind(GLAutoDrawable drawable) { drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); if (!valid) validate(drawable); System.out.println(program); gl.glUseProgram(program); } public void release(GLAutoDrawable drawable) { drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); gl.glUseProgram(0); }
int program; boolean valid = false; URL vert_url; URL frag_url;
} |
|
|
|
|
|
30
|
Java Game APIs & Engines / JOGL Development / Re: displacement mapping?
|
on: 2008-11-02 14:19:49
|
OpenGL currently can only displace vertices, so if you have a sea of only a few triangles, it's hard to do any real displacement. But if you tessellate your geometry, you can have use your vertex shader and a texture lookup or a procedural function like Perlin noise to displace the vertex before going to the fragment shader. If you handle the normal in the vertex shader, most of the fragment shader is just the texture lookup. If you want a good example, you can track down the code for Java Monkey Engine's water demo. Click on 'run demo' for the water demo below if that's what you're interested in doing. http://www.jmonkeyengine.com/movies_demos.php
|
|
|
|
|