OpenGL Beginning to work with GLSL

Recommended Posts

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

Share on other sites
I'd use ATI's RenderMonkey rather than Shader Designer - much better - got me started on GLSL in a few hours :)

Share on other sites
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]

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

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

...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

Share on other sites
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);

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

Share on other sites
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'.

Share on other sites
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();

Much thanks.

Share on other sites
Heh, most sites say to use GLEW or similar so they can concentrate on the GLSL more. In summary what I do is (windows code):

#define WIN32_LEAN_AND_MEAN#include <windows.h>#include "glext.h" // Make sure its a later edition header....// Shader extensions: (upper case defs are in glext.h)PFNGLCREATESHADEROBJECTARBPROC		glCreateShaderObjectARB = 0;PFNGLSHADERSOURCEARBPROC			glShaderSourceARB = 0;// so on for all required fns...void CheckGlExtensions(){	char* supportedExtensionsString = (char *) glGetString(GL_EXTENSIONS);	if (strstr(supportedExtensionsString, "GL_ARB_shader_objects"))	{		if (strstr(supportedExtensionsString, "GL_ARB_shading_language_100"))		{			LOG("GL_ARB_shading_language_100 supported");			glCreateShaderObjectARB		= (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB");					glShaderSourceARB			= (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");// so on for all required fns...		}	}}...// Now the ARB functions are ready for use.

GLUT is a separate wrapper framework for quick use of OpenGL fixed pipeline stuff (not shaders last time I looked at it).

Ed: Looks like GLEW might depend on GLUT though...

[Edited by - Aph3x on March 14, 2007 8:18:08 AM]

Share on other sites
Thanks.

compare to:

would this code also go in the latter if block in your code:

const char * vv = vs;
const char * ff = fs;

free(vs);free(fs);

p = glCreateProgramObjectARB();
glAttachObjectARB(p,v);
glAttachObjectARB(p,f);

glUseProgramObjectARB(p);

I have a procedure (which I pretty much modified from lighthouse during my testing phase) which is called setshaders and I call it when the program loads. I want to apply it to a model or primitive that I've already loaded into my code (that much I have done). I'm also not so sure your code will work with mingw..?

Share on other sites
My lines there are just setting up the function pointers to the ARB extensions. This is what things like GLEW do for you.
Your code there seems to be actually *using* the functions to create a shader object.
You have to compile and create a shader program, then 'use' it before rendering the object in question. When you use the program, the programmable pipeline kicks in for the consecutively submitted geometry. Don;t forget to UseProgram(0) when finished (return to fixed pipeline).

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627676
• Total Posts
2978588
• Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 12
• 10
• 12
• 22