I'm trying to figure out how to start using GLSL with JOGL to do pixel shading on images drawn to GLAutoDrawable via glDrawPixels.
I'm confused as to how a few things work in GLSL:
1) How can I access the color of the current pixel in the shader call? What is the form of that pixel (RGB, BGR, etc.) so that I can unpack it?
2) Do I just assign gl_FragColor to change the pixel?
3) How do I get coordinates of the current pixel?
4) When is glSwapBuffer() necessary?
I've now been told not to use glDrawPixels, which now confuses me even further.
Which adds the new question:
5) What is the most generally reliable method of loading an image and rendering it on a GLDrawable?
Your answer is, unfortunately, no longer there.... I don't know why.
The "current pixel" is not known. If you want post-processing, then typically you would render the screen to an FBO texture, and then in your post shader sample from the texture in order to "get the screen pixel."
That makes sense... but I don't really know how to do it. Does anyone know of any examples of that ^?
Why does the fact that shaders run in parallel mean the current pixel isn't known? What can a frag shader do without knowing the pixel color?
Update: Ok I found a pretty decent shader example here.
But what is going on with:
uniform sampler2D fish_y_offset;
and why does it never get assigned to anything? Does GLSL do that automatically?
I also don't really get what's happening with this:
gl_FragColor = texture2D(fish_y_offset, gl_TexCoord.st);
And since texture2D is now deprecated, what's the now accepted way to do that?
Your answer is, unfortunately, no longer there.... I don't know why.
My answer has been moved by the moderator, I prefer posting it anew here:
Why do you want to use glDrawPixels?
1) The role of a pixel shader consists in computing the color. What do you really want to access?
3) Pixel shaders have knowledge of the screen coordinate being drawn, it should be possible, use gl_FragCoord.
4) I would rather use GLSL to perform light computations, for example per pixel lighting.
I remind you that questions specific to any JogAmp APIs including JOGL should be posted on our official forum. Ok I will try to find a similar example using JOGL 2.0.
Edit.: Rather use GLOffscreenAutoDrawable or a simple texture mapped in a quad, it will be more reliable. glDrawPixels might not work very well with GLSL on some hardware.
I advise you to read a basic course about shaders as you seem not to understand which variables are in input and in output in a shader of a particular type (vertex, pixel, geometry, ...).
I've been reading about shaders, but I'm more confused about JOGL and GLSL specifically.
If you have any particular article or shader-tutorial you would like me to read before continuing my inquiries, please post it, and I will be happy to do so.
The reason this isn't entirely general OpenGL is because I'm looking for examples of doing this in JOGL. I want to figure out how to write the shader AND interface with it properly from the Java code, which is clearly in JOGL, not LWJGL or anything else.
Ok I'm going to try and clarify what I'm trying to do here so that maybe it will be easier for you guys to point me in the right direction:
I want to be able to have a collection of renderable objects that contain loaded BufferedImages (sprites) that can render their content to a central frame renderer. In my Java2D renderer, I did this by passing around a Graphics2D object generated by a VI.
I am first planning on writing class that would perform the necessary conversions and transformations to a BufferedImage on load.
I am using a FPSAnimator to control the rendering loop.
The reason I want a shader is for enabling gamma correction on rendered frames (and possibly lighting later on).
I'm stuck right now on how I should be collectively rendering the images. Should I be loading them as Textures and drawing them as quads? Or should I be using glDrawPixels?
>The reason this isn't entirely general OpenGL is because I'm looking for examples of doing this in JOGL.
> I want to figure out how to write the shader AND interface with it properly from the Java code, which
>is clearly in JOGL, not LWJGL or anything else.
You don't need glDrawPixels. You can use shaders with the helpers specific to JOGL or using the same methods you would call in plain C.
Personally, I love this tutorial even though it is a bit old. I gave you 2 examples in my previous post, have you understood them? I can show you how I use shaders in Ardor3D and JMonkeyEngine. Demoscene Passivist has some excellent examples too.
You can do gamma correction and lighting directly in the fragment shader.
2013-03-25 20:37, bgroenks96 [via jogamp] skrev:
> gouessej wrote
> I advise you to read a basic course about shaders as you seem not to understand which variables are in input and in output in a shader of a particular type (vertex, pixel, geometry, ...).
> I've been reading about shaders, but I'm more confused about JOGL and GLSL specifically.
> If you have any particular article or shader-tutorial you would like me to read before continuing my inquiries, please post it, and I will be happy to do so.
Shaders are passed in clear text Strings to your GPU driver. The GPU driver compiles the shader for use by the processing units on your device.
The syntax for shaders differs slightly depending on which OpenGL version you target:
Most of the JogAmp examples uses mobile and desktop compatible GLSL syntax and are using the GL2ES2 profile that is supported on both OpenGL 2 and ES 2 hardware.
OpenGL 2 and ES 2 shaders uses similar keywords inside the GLSL language thus it is possible to write Vertex and Fragment shaders in a way that work on both desktop and mobile by using the GLSL GPU compilers preprocessor to hide keywords that are specific to mobile OpenGL ES 2.
The quick way to make a Vertex or Fragment shader OpenGL 2 and ES 2 compatible is by placingthe following 4 lines at the top of the Vertex and Fragment shader:
Below I will list the latest OpenGL specifications and how they differs from the above OpenGL 2 and ES 2:
OpenGL 4.3 (desktop) adds support for three new kind of shaders:
Tessellation Control Language
Tessellation Evaluation Language
http://www.khronos.org/files/opengl43-quick-reference-card.pdf You also notice that some of the shader keywords have changed from the OpenGL 2 to OpenGL 4.3
The "variant" keyword is now renamed to "out" inside the vertex shader
The "variant" keyword is now renamed to "in" inside the fragment shader
It looks like there will be possible to create a new desktop and mobile profile possibly called GL43ES3 that may be both OpenGL 4.3 and ES 3 compatible that can be used by the latest OpenGL hardware on both mobile and desktop.
Online tutorials for OpenGL 2 up to OpenGL version 3.3:
Thanks guys. That's a lot of examples. Let me look through all of these and I will let you know how I'm doing after that.
And I'm fine with using TextureIO directly rather than doing everything from AWT. I wasn't expecting the OpenGL renderer to work with existing Java2D dependent code. As long as I can load data from a URL, I'm all for it.
On 04/06/2013 01:38 AM, bgroenks96 [via jogamp] wrote:
> Sorry, it's been a while.
> Would it be possible to have the shader run with or without a bound texture?
> I was thinking maybe a check in the shader the uses a manually set color
That is one extension I had in mind as well,
and while modularizing them .. I may have a chance to add it.