OpenGL 3/4 - 3D Without Lights, and Shader Basics

Started by
3 comments, last by gbMike 11 years, 8 months ago
I'm having a great deal of difficulty making the switch from opengl 2, up to 3.1+. Specifically, with shaders.

I've found tons of tutorials, with lots of example shader files, with descriptions of what the files do, but I don't understand the specifics of exactly how they work. Here is an example from one of swiftless's tutorials:


#version 150 core
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
in vec3 in_Position;
in vec3 in_Color;
out vec3 pass_Color;
void main(void)
{
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0);
pass_Color = in_Color;
}


I don't understand how the engine knows what to do with what. From what I can see, apart from the keyword 'in/out/uniform' this defines some variables, and initializes 2 of them on shader creation. I just don't understand how that, translates to gl shader calculations. Anyone know any good resources that focus specifically on line by line shader creation? (Preferably at a more fundamental level)
Advertisement
gl_Position acts just like it does in GL2.
in variables act like generic vertex/normal arrays. When you upload vertex data from your opengl program, you tell it which variable (in_Position,in_Color) to link it to. Each vertex in the array you upload goes to the vertex shader once.
Out variables are like varying variables. They get interpolated and given as INputs in the fragment shader, which knows they're the same because they have the same name.
If you understood GL2 shaders all you need to recognize is that with GL3 there are less hard-coded variables. Instead of using gl_Normal to pass a variable to the fragment shader, you just make your own variable called normal
Thanks, that is very helpful.


If you understood GL2 shaders all you need to recognize is that with GL3 there are less hard-coded variables.


Unfortunately for me, I never learned anything about shaders with GL2. The engine I had built, had flat lighting, and diffuse texture support only. Even now, that is all I need to support, but it seems working with the latest opengl version necessitates learning shaders.
Look at the Learning Modern 3D Graphics Programming, it will quickly make you understand how to use shaders.
[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/
That is exactly what I was looking for. Thanks!

This topic is closed to new replies.

Advertisement