Jump to content
  • Advertisement
Sign in to follow this  
gbMike

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

This topic is 2171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!