1

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):

If I remove #include <GL3/gl3w.h> and glewInit(); the texture is successfully loaded.

Merigrim
  • 846
  • 10
  • 18
  • ["Supports all OpenGL versions up to version 3.1 standard and additional OpenGL, WGL and GLX extensions."](http://www.gremedy.com/gDEBuggerGLFeatures.php) Since you don't seem to be *displaying* your loaded texture anywhere I assume you're just using gDEBugger to see if it loads correctly? – genpfault Nov 10 '11 at 23:18
  • Yeah, that is correct. However, even if I set the context version to 3.1 it still doesn't work. And I tried drawing it too, but it didn't show up even outside gDEBugger, however the vertices did if I set the fragment shader to use a solid color instead. – Merigrim Nov 11 '11 at 00:10

0 Answers0