Tutorial 4 - Introduction to Shaders in OpenGL (code)

preview_player
Показать описание
This tutorial shows how to compile and use shader programs in OpenGL.
Рекомендации по теме
Комментарии
Автор

Man, you really know how to convey your knowledge quickly and efficiently. Thanks for this series of tutorials, there are really promising.

WingedEver
Автор

I'm so happy I found this... Thanks for not using fancy c++.

alexmercerind
Автор

I wound up debugging your code in a question on Stack Overflow, and you should be aware that you have an off-by-one index problem with your attempt to NULL terminate the shader string. This is probably why the program crashes for many people. At 0:41, if you look at line 20, that should read *contents[file_length] = '\0';* Otherwise, you are trying to write the NULL terminator 1 character after the end of your allocated memory. _That errant line is altogether unnecessary since you already zeroed the entire array though (including the 1 extra byte you allocated for the NULL terminator)._

MrGencyExit
Автор

Well, if you get compile errors for your shader, then the project will still run, but you get a black screen; check the DOS screen and you will likely see a bunch of -1s for the IDs. For the shader code (the .vsh and .fsh files), maybe try manually adding them to the project in VS?

jeffchastine
Автор

If it's not in any of the projects, it's probably easiest (and a good exercise) to watch the video and type in the file. It's only a few lines of code :)

jeffchastine
Автор

I need to go back and look at the code, but the basic ideas is that the word "cat" takes four characters because of the null termination (i.e. the escape sequence that you see).

jeffchastine
Автор

contents[file_length+1] = '\0'; is wrong, it's writing past the end of the string. If the shader is 100 bytes long, new char will allocate 101 bytes, which is correct (i.e. indices 0 to 100) but then the effective instruction is contents[101] = '\0'; unless I've made a mistake?

TheWeepingCorpse
Автор

Actually I changed the properties of those files by right clicking on them in VS and selecting "Does not participate in build".
But now when I compile, the window is just black with no triangles in it.
What do you mean by path ?
The project path is: studio 2012\Projects\OpenGl Project\OpenGl Project

aramazhari
Автор

Actually it won't run because it won't compile. As I said, I specified the "does not participate in build" from properties options of those files. Now the project runs. But I still get a black screen.
The ID for the vertex shader is 1, and for the frag shader is 2

aramazhari
Автор

What version of glew did you use for these awesome tutorials?

DiJeGoLife
Автор

so, what's the result of this code?

igghquu
Автор

Ugh - that's bizarre. It looks like a NULL pointer (from the I hate to say it, but try it on another machine and see if you get the same error? Also, run it in Debug mode and perhaps you can gain some insight by setting a breakpoint (if you don't know how to do that, please let me know).

jeffchastine
Автор

Is this source-code available for downloading somewhere?

MateusChagasSousa
Автор

In visual studio 2012, I get compile error from shader files. Why?
Error 4 error C2065: 'gl_Position' : undeclared

aramazhari
Автор

Hey, just wondering, what version of openGL are you using in these tutorials?

MariusSemeonOrtiz
Автор

for some reason i get an access violation error

Unhandled exception at 0x7530C9F5 in Void Explorer.exe: Access violation executing location

in this part:

GLuint makeVertexShader(const char* shaderSource)
{
(this line)=> GLuint vertexShaderID =
glShaderSource(vertexShaderID, 1, (const GLchar**) &shaderSource, NULL);

return vertexShaderID;
}

lolgamer
Автор

Maybe after my students are done with their projects :)

jeffchastine
Автор

can you post a li k to downloads of tbe new code... on ALL of your videos? that would be nice.

bobiscool
Автор

Hi Jeffrey, Thanks for the video. After executing your shader example code, I get a white screen with a wait symbol. I am wondering is there something wrong? Aren't we supposed to get a red image on the window?

jayakarthick
Автор

Hello, thanks for tutorials! Could you re-upload fragment file, because i could not find it. Thanks! :)

DiscoFlavor
visit shbcf.ru