Jump to content
  • Advertisement
Sign in to follow this  
Neutrinohunter

OpenGL GLSL Basics

This topic is 3904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 Shader

uniform 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!