I can NOT see what Im doing wrong here. Im using OpenGL and have this vert shader:
[B]void main()[/B]
[B]{[/B]
[B] gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;[/B]
[B] gl_FrontColor = vec4( 1.0, 0.5, 0.25, 1.0 );[/B]
[B]}[/B]
And this fragment shader:
[B]void main()[/B]
[B]{[/B]
[B] gl_FragColor = gl_Color;[/B]
[B]}[/B]
No matter what I do, the primitives are always drawn as white. If I introduce errors into these shaders, my program complains so its clearly compiling and running the right ones.
Is there anything inherently wrong with what Im doing here? I cant imagine so, but I wanted to double check. Something Ive overlooked?
These SHOULD work
right?
Replies
It's from a C# app I'm toying around with.
If I try your code as written my app kicks up an error:
You are probably using opengl 3.3 or higher without a compatibility profile.
Try it with those below.
Vert: Frag: Why are you defining a the color in the vertex shader when the color is constant over all verts? It could be done simpler if you do it in the fragment shader.
Vert: Frag:
BUT, the second set of code compiled fine ... now, what I don't understand is that if I use the vertex and fragment shader together, the mesh renders white. If I only use the fragment shader, it renders in the color specified.
Any thoughts on that?
And I apologize for, what I'm sure, are super basic baby questions but I really am kind of in the dark on this. I haven't coded in years and I'm pretty rusty. However, I got a mesh loading and drawing so there's hope! :P
At any rate, I appreciate you taking the time.
As for:
Because I'm sort of noodling trying to see if I can make anything happen via shaders. I'm sure I'm not taking the optimal route to anything...
I have the orange book for shaders and am reading it but I can't get a basic shader working yet so it's sort of a roadblock. An annoying one...
Thanks a ton! I can finally start experimenting ...
There are many ways to code is glsl and opengl. It depends on the version you are targeting and what functionality you require.
Here are 2 articles on the history of opengl:
http://en.wikipedia.org/wiki/OpenGL
http://en.wikipedia.org/wiki/OpenGL_Shading_Language
Good luck with your app.
Life should be easier by using a GLSL ide / offline compile tool. I am working on the shader related parts of an opensource IDE primarily meant for Lua. It originated from the luxinia engine and is now mostly maintained by someone else as zbstudio
http://studio.zerobrane.com/
the original editor was estrela and both now share more or less the same code-base
https://sourceforge.net/p/estrelaeditor/code/ci/master/tree/
current snapshot as download, just unzip and run exe no installation required.
http://sourceforge.net/code-snapshots/git/e/es/estrelaeditor/code.git/estrelaeditor-code-e886befe4cdb75ad54b2b9424a269a941a93699f.zip
It has frontends to dx and glsl offline compilers, so you can easily check the shader syntax prior launching app.
to enable the "estrela" legacy path with the glsl, hlsl support:
* copy and rename the cfg/estrela.lua to cfg/user.lua
for GLSL
download https://github.com/CrazyButcher/glslc
either set a global environment variable GLSLC_BIN_PATH to the glslc/bin_Windows_32 directory or edit the user.lua file so that it looks a bit like this
for HLSL: download install directx sdk, the path the dx compiler is automatically found as the DX sdk installation sets the path.
Hope that helps, I typically try to keep the tools up to date, as I use them at work more or less daily. glslc outputs a bit more information when used on a system with NVIDIA, but should work on AMD or Intel, too (however, I hardly test that).