GLSL Basics

Started by
7 comments, last by Neutrinohunter 16 years, 3 months ago
I have been reading GLSL Basics as I am trying to implement a Shader Library into an application I'm writing and I'm a little stuck. As far as I can tell my system supports OpenGL Version 2.1 (QT Code is saying this), however when I try to compile using the gl.h/glext.h headers I get undeclared functions for the glsl basic creation functions (glCreateShader, glAttachShader etc). Do I need to update my gl.h/glext.h files? Function Pointers Needed? I've read about five/six different tutorials and not one has mentioned getting basic features sorted inside the compiler. Anything I'm missing/misunderstanding? neutrinohunter
Advertisement
you need to intialize all functions that are above OpenGL 1.1 or so..

GLee or GLEW make this easier for useage (google for them + opengl)
This explains why and what
http://www.opengl.org/wiki/index.php/Getting_started
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I would definitely recommend using GLee for this, rather than messing around with doing it yourself. You wont gain anything whatsoever by doing it yourself, and you have the added bonus that GLee is well tested, etc.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

If you are using Linux or MacOS then you shouldn't be getting this. Only Windows users have this problem since Microsoft has been trying to kill OpenGL and hasn't updated their OpenGL stuff in over 10 years. One of the many reasons to abandon that piece of crap and migrate to a real OS...
-----------------------------Join us at iClips. We are developing a cool 3D virtual world to go with our livestreams. Email me.look here
Quote:Original post by dumbsnake
If you are using Linux or MacOS then you shouldn't be getting this. Only Windows users have this problem since Microsoft has been trying to kill OpenGL and hasn't updated their OpenGL stuff in over 10 years. One of the many reasons to abandon that piece of crap and migrate to a real OS...


Hmm, not really fair. MS don't consider OpenGL one of their concerns, but its not fair to say they have been "trying to kill" it. They just don't see any profit in supporting it.
I'm actually using as many as possible. I currently have versions for Linux, Windows and am hopefully going to get a Mac and a Solaris version working.

And IIRC don't you require function pointers for all the OS's you try on?

Thanks to everyone who helped with this, haven't got stable output with a shader yet but I have a library implemented. Thank you.
I'm using glew with QT in my project. There are only 2 important things:
1. The glew include have to be the first include.
2. The glewInit() function have to be called one time in initializeGL() of any QGLWidget based class.
It is recommend to include glew into the QT project, because it's simplify the portability
Thanks, im managed to get that to work now.

I am using GLEE for the moment, I believe thats as portable as GLEW so unless I have a problem I'll stick with that. Thanks for the info oc2k1.

I've been looking at OpenGL Shading Language Second Edition and trying out some of the examples. Now all of them have worked more or less but the Shadow Map one is causing me a bit of trouble.

I get a shadow (it seems) that follows my camera, not sure what the problem
http://img90.imageshack.us/img90/8022/image1wi7.jpg

attribute float Accessibility;varying vec4 ShadowCoord;// Ambient and diffuse scale factors.const float As = 1.0 / 1.5;const float Ds = 1.0 / 3.0;void main(){    vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;    vec3 ecPosition3 = (vec3(ecPosition)) / ecPosition.w;    vec3 VP = vec3(gl_LightSource[0].position) - ecPosition3;    VP = normalize(VP);    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);    float diffuse = max(0.0, dot(normal, VP));    float scale = min(1.0, Accessibility * As + diffuse * Ds);    vec4 texCoord = gl_TextureMatrix[1] * gl_Vertex;    ShadowCoord   = texCoord / texCoord.w;    gl_FrontColor  = vec4(scale * gl_Color.rgb, gl_Color.a);    gl_Position    = ftransform();}Fragment Shaderuniform sampler2DShadow ShadowMap;uniform float Epsilon;varying vec4 ShadowCoord;float lookup(float x, float y){    float depth = shadow2DProj(ShadowMap,                      ShadowCoord + vec3(x, y, 0) * Epsilon).x;    return depth != 1.0 ? 0.75 : 1.0;}void main(){    float shadeFactor = lookup(0.0, 0.0);    gl_FragColor = vec4(shadeFactor * gl_Color.rgb, gl_Color.a);}


Not sure what to make of it, I thought it would pretty much work out of the box so to speak as it was in a book. Any ideas on what's causing it, how to fix?

Neutrinohunter

This topic is closed to new replies.

Advertisement