Beginning to work with GLSL

Started by
11 comments, last by MGB 17 years, 1 month ago
I want to begin working with GLSL to create object shaders. I started at Lighthouse3D Tutorials, downloading the GLSL ARB Extensions Syntax VC code, which compiles fine. http://www.lighthouse3d.com/opengl/glsl/index.php?minimal There are two lines: vs = textFileRead("minimal.vert"); fs = textFileRead("minimal.frag"); which appears to attach the vertex and fragment shaders to the rendered model in the Visual Studio project. As I began testing, I downloaded TyphoonLabs Shader Designer and opened, modified a basic lighting shader. I noticed the Shader Designer also had several other predesigned shader projects, with vert and frag files. However, if I just change the text file parsing to read the sample files (i.e. vs = textFileRead("stripes.vert");) it doesn't work -- the model stays a single, black entity. The Shader Designer syntax looks pretty straight-forward, but how can I get this implemented into a Visual Studio OpenGL project?
Advertisement
There's something you should take into account when programming with GLSL, for example the function glShaderSource takes as input the actual shader code as a C-string (i.e. null terminated).

Perhaps the textFileRead() function in Lighthouse3D tutorial is reading the file in some different way.
I'd use ATI's RenderMonkey rather than Shader Designer - much better - got me started on GLSL in a few hours :)
Thank you for your help so far.

I downloaded RenderMonkey, put a model in and added some effects. I then pulled up the vert and frag code windows, copied and pasted the code into .frag and .vert files and tried again. Still no luck. I tried opening the lighthouse code and using these files and the teapot still shows up all black, and I thought it would have my texture, lighting effects in RenderMonkey.

I understand how to load 3ds files, models, etc. using OpenGL and I think I understand how these editors work. But I am missing the connection between the two, it seems.

and didn't know if anyone want to take a look. I'm either (a) not exporting the shader information correctly or (b) not understanding how lighthouse loads a shader and applies it to a model. Can't seem to find any RenderMonkey GLSL tutorial anywhere...

[Edited by - rm2000 on March 12, 2007 11:24:42 AM]
You are not passing the "uniform" and "varying" variables to the shader.

I'm pretty sure lighthouse3D explains what they are and how to use them.
Thank you GamerYZ that seemed to be the problem.

An additional question if I may, I'm trying to get this to compile (now) using Code:Blocks (MINGW) instead of Visual Studio. I keep getting linker errors:

i.e.

undefined reference to '_imp____glewCreateShaderObjectARB'
undefined reference to '_imp____glewCreateShaderObjectARB'
undefined reference to '_imp____glewCreateShaderObjectARB'
undefined reference to '_imp____glewShaderSourceARB'

...etc...etc

I have included glew.h and glut.h into the file as an include and I have set my link libraries to:

libopengl32.a
libwinmm.a
libglu32.a
libglut.a
libglu32.a
glew32s.lib
glew32.lib

glew32.dll has been copied to %SYSROOT% and to the codeblocks lib folder

(I use some of the other libraries for other parts of my code). Am I missing anything else?

Thanks again
Are you initializing glew and making sure glew knows where the functions are (if i remember correctly the glew documentation goes into detail on getting entry points to the correct functions);
www.lefthandinteractive.net
Everything, code-wise, seems to be okay. The same project builds fine under Visual Studio. I did notice the glew lib extensions are .lib where the ones for codeblocks are .a.
Setting up the extensions isn't at all hard to do manually - I'd try it yourself rather than using GLEW, and then you know exactly what's going on rather than relying on the GLEW 'magic'.
Maybe I'll try giving that a shot. Any good sites for reference? I was able to finally get it to build by attaching the glew32.dll file (not the library). It doesn't make a whole lot of sense to me why the dll worked.

If I may continue the conversation further, do I need to use GLUT to use these extensions? I was able to set up a window using GLUT and such, but if I draw a Window and use just OpenGL I get the no GLSL support on the following:

glewInit();

if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)

Much thanks.

This topic is closed to new replies.

Advertisement