Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 gbMike   Members   -  Reputation: 152

Like
0Likes
Like

Posted 06 August 2012 - 11:11 AM

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)

Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
1Likes
Like

Posted 06 August 2012 - 11:36 AM

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

#3 gbMike   Members   -  Reputation: 152

Like
0Likes
Like

Posted 06 August 2012 - 12:48 PM

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.

#4 larspensjo   Members   -  Reputation: 1557

Like
1Likes
Like

Posted 06 August 2012 - 01:14 PM

Look at the Learning Modern 3D Graphics Programming, it will quickly make you understand how to use shaders.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#5 gbMike   Members   -  Reputation: 152

Like
0Likes
Like

Posted 06 August 2012 - 02:06 PM

That is exactly what I was looking for. Thanks!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS