When I use GL3W, I cannot load textures. They appear blank or messed up.
I wanted an OpenGL 4.2 context in SDL 1.3 and so I decided to use GL3W, as GLEW used deprecated functions. Everything seems to work fine, however, when I try to load a texture, it either gets messed up (randomly colored lines) or simply ends up blank (black without alpha, transparent with). Everything else I've tried so far has worked (shaders, VAO's, VBO's, etc.)
I wrote the most simple example I could come up with to illustrate:
#include <SDL.h>
#include <SDL_image.h>
#include <GL3/gl3w.h>
#include <gl/gl.h>
#include <gl/glu.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_WindowID mainWindow = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GLContext mainContext = SDL_GL_CreateContext(mainWindow);
SDL_GL_MakeCurrent(mainWindow, mainContext);
gl3wInit();
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
SDL_Surface* test2 = IMG_Load("test.png");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, test2->w, test2->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, test2->pixels);
// Loop to keep the window open while debugging in gDEBugger
while (1) {
SDL_GL_SwapWindow(mainWindow);
}
return 0;
}
I don't know how relevant it is, but since gl3w is generated by a python script I'll include it (external links because of length):
- gl3w.c: http://pastebin.com/T5GNdJL8
- gl3w.h: http://pastebin.com/yU2EzBZP
- gl3.h: http://pastebin.com/0uCgB8d1
If I remove #include <GL3/gl3w.h>
and glewInit();
the texture is successfully loaded.