Sign in to follow this  
transistor09

Is GLEW necessary to use shaders? [solved: NOT necessary]

Recommended Posts

I've been able to use shaders with GLEW but now I'm trying to wglGetProcAddress manually. It doesn't leave empty pointers but doesn't work either. I define the funtions
typedef GLuint (APIENTRY * PFNGLCREATESHADERPROC) (GLenum type);
PFNGLCREATESHADERPROC glCreateShader = NULL;

//later
glCreateShader = (PFNGLCREATESHADERPROC) wglGetProcAddress ("glCreateShader");
if (!glCreateShader) MessageBox (hwnd, TEXT("fail at glCreateShader"), L"ERROR", MB_OK | MB_ICONSTOP);

//finally
vert = glCreateShader (GL_VERTEX_SHADER);
Same with glShaderSource, glCompileShader, glCreateProgram, glAttachShader, glLinkProgram, glUseProgram. No warnings, no errors, no hangs, just the same old fixed function. So is GLEW (or any other lib for that matter) necessary or am I missing something? [Edited by - transistor09 on February 10, 2010 11:00:45 AM]

Share this post


Link to post
Share on other sites
My code seems to be doing the same damn thing; no cookie though.

FILE * sourceFile = fopen ("shaders/vert", "rb");
fseek (sourceFile, 0, SEEK_END);
unsigned long size = ftell (sourceFile);
rewind (sourceFile);
char * source = (char *) malloc (size + 1);
size = fread (source, 1, sizeof (char), sourceFile);
source[size] = 0;
vert = glCreateShader (GL_VERTEX_SHADER);
glShaderSource (vert, 1, (const char **) &source, NULL);
glCompileShader (vert);

sourceFile = freopen ("shaders/frag", "rb", sourceFile);
fseek (sourceFile, 0, SEEK_END);
size = ftell (sourceFile);
rewind (sourceFile);
source = (char *) realloc (source, size + 1);
size = fread (source, sizeof (char), size, sourceFile);
source[size] = 0;
frag = glCreateShader (GL_FRAGMENT_SHADER);
glShaderSource (frag, 1, (const char **) &source, NULL);
glCompileShader (frag);

fclose (sourceFile);
free (source);

prog = glCreateProgram ();
glAttachShader (prog, vert);
glAttachShader (prog, frag);
glLinkProgram (prog);
GLint linked;
glGetProgramiv (prog, GL_LINK_STATUS, &linked);
if (linked) MessageBox (hwnd, TEXT("program liked"), L"message", MB_OK | MB_ICONSTOP);



I get no "program liked" message

Share this post


Link to post
Share on other sites
Quote:
Original post by transistor09
So is GLEW (or any other lib for that matter) necessary or am I missing something?
GLee/GLEW are not in any way necessary, but they exist to make your life easier. Unless you are working on a 4k intro, I see little point in putting yourself through the hell that is the OpenGL extensions mechanism.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
[...] Unless you are working on a 4k intro, I see little point in putting yourself through the hell that is the OpenGL extensions mechanism.


Is it really that hard?

I just don't know which lib is the best so I'm trying to do with no lib at all

Share this post


Link to post
Share on other sites
Quote:
Original post by transistor09
Quote:
Original post by swiftcoder
[...] Unless you are working on a 4k intro, I see little point in putting yourself through the hell that is the OpenGL extensions mechanism.
Is it really that hard?
It isn't hard at all - it is just pages and pages of boilerplate code that someone else has already written for you.
Quote:
I just don't know which lib is the best so I'm trying to do with no lib at all
Take this argument to its conclusion, and you will wind up implementing your own OS because "I don't know whether Windows or Mac is better" [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by transistor09
Despite that, have anything to recommend, swiftcoder?
I never tried GLEW - GLee was simpler to install on a Mac back when I discovered it, so that is what I have used ever since. It is about zero hassle - compile it in or link to it, and include GLee.h instead of GL.h.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by transistor09
Despite that, have anything to recommend, swiftcoder?
I never tried GLEW - GLee was simpler to install on a Mac back when I discovered it, so that is what I have used ever since. It is about zero hassle - compile it in or link to it, and include GLee.h instead of GL.h.


Just as a little aside, GLEW is now incredibly easy on the Mac. Download, run Make, put in /usr/local/lib and /usr/local/include respectively.

No fuss.

Share this post


Link to post
Share on other sites
Umm, scratch that, there was an error (you can clearly see it in my posted code) in my file loader. Everything works fine without GLEW.

For me, binding extensions is easier than converting a VC6 project to work with CodeBlocks.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-manI like GLEW. It makes my program run 5 times faster. You have to call glewInit.
Please tell me that's a joke. On the small chance you're serious... why so? Also, do you need to call the glewInit() function if you compile the GLEW files into your program (and thus not link it in)?

Share this post


Link to post
Share on other sites
Quote:
Also, do you need to call the glewInit() function if you compile the GLEW files into your program (and thus not link it in)?

Yes. I bet its the function that GLEW uses to bind extensions. If you try to use any function before glewInit(), the program fails. [GL]Extensions are done differently than linking. You have to manually initialize the function pointer to it's prototype.

Share this post


Link to post
Share on other sites
Quote:
Original post by transistor09
Quote:
Also, do you need to call the glewInit() function if you compile the GLEW files into your program (and thus not link it in)?

Yes. I bet its the function that GLEW uses to bind extensions. If you try to use any function before glewInit(), the program fails. [GL]Extensions are done differently than linking. You have to manually initialize the function pointer to it's prototype.
Correct. However, GLee handles this under the hood (unlike GLEW).

Share this post


Link to post
Share on other sites
Quote:
Original post by maxgpgpu
Quote:
Original post by V-manI like GLEW. It makes my program run 5 times faster. You have to call glewInit.
Please tell me that's a joke. On the small chance you're serious... why so? Also, do you need to call the glewInit() function if you compile the GLEW files into your program (and thus not link it in)?


It was a joke. This thread seems kind of too boring for my taste.
Anyway, GLEW is the best.
GLEE, every time you call a gl function, GLEE checks to see if it has initialized. It might not have an effect on performance, but I prefer GLEW's way.

Have fun with GL!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this