Beginning to work with GLSL

Started by
11 comments, last by MGB 17 years, 1 month ago
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]
Advertisement
Thanks.

How does your line:

glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");

compare to:

v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
f2 = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

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

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

glShaderSourceARB(v, 1, &vv,NULL);
glShaderSourceARB(f, 1, &ff,NULL);

free(vs);free(fs);

glCompileShaderARB(v);
glCompileShaderARB(f);

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

glLinkProgramARB(p);

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

This topic is closed to new replies.

Advertisement