Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 23 Oct 2011
Offline Last Active Apr 14 2012 12:32 PM

Topics I've Started

Having loads of trouble compiling C++ SDL/OpenGL project on Mac OS X

10 April 2012 - 03:09 PM

We've been encountering many barriers in our attempts to compile our SDL/OpenGL game on Mac OS X. The main development OS is Windows but we've also had no problem building the game for Linux operating systems.

The preferred method of library distribution on OS X is through frameworks, and SDL is no different. Since SDL has several sub-libraries, each in a separate framework, the #include code is different between systems. (The OpenGL #include code is also different, for the record.)

#ifndef __APPLE__
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <OpenGL/gl.h>
#include <SDL/SDL.h>
#include <SDL_image/SDL_image.h>
#include <SDL_mixer/SDL_mixer.h>

This is all fine and dandy but that actually gives me compilation errors in the frameworks' headers themselves, as they refer to files from other parts of SDL with the assumption they're in the same folder. One could edit the headers but other errors happen then. Since frameworks are the "proper" way of distributing libraries in your application bundles, I'm going to assume that there's just something wrong on my end and not that SDL frameworks are completely unusable by anyone.

In addition, a perturbing problem with OpenGL is that it insists that GLuint is not defined. This is baffling, considering you can go to OpenGL/gl.h yourself and plainly see the typedef of GLuint.

I've been struggling with these issues for a while and I'd appreciate it if someone would be able to help with this.

OpenGL textures loaded with SDL_Image display with no alpha

23 October 2011 - 09:44 PM

I am making a game using OpenGL, with SDL_Image employed to load the textures. When drawn on screen, there's no alpha -- in an exact square around the opaque contents of the texture, black is drawn; outside that space, white is drawn. Here is my OpenGL init code...

    SDL_SetVideoMode(windowWidth, windowHeight, 16, SDL_HWSURFACE|SDL_GL_DOUBLEBUFFER|SDL_OPENGL);
    glClearColor(0, 0, 0, 0);
    glViewport(0, 0, windowWidth, windowHeight);
    glOrtho(0, windowWidth, windowHeight, 0, 1, -1);

...here is my image loading function...

    SDL_Surface *loadImage (const char *filename, bool alpha = true) {
        SDL_Surface* loadedImage = NULL;
        SDL_Surface* zoomedImage = NULL;
        SDL_Surface* optimizedImage = NULL;

        loadedImage = IMG_Load(filename);

        if (loadedImage != NULL) {
            zoomedImage = zoomSurface(loadedImage,windowScaleH/4,windowScaleH/4,SMOOTHING_ON);

            if (alpha) optimizedImage = SDL_DisplayFormatAlpha(zoomedImage);
            else optimizedImage = SDL_DisplayFormat(zoomedImage);

        return optimizedImage;

...here is the code I actually use to create the GL texture...

    GLuint thisIsMyTexture;
    glGenTextures(1, &thisIsMyTexture);
    temporarySurface = loadImage("theimagetomytexture.png");
    glTexImage2D(GL_TEXTURE_2D, 0, 4, temporarySurface->w, temporarySurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temporarySurface->pixels);

...and the drawing code itself.

    glBegin( GL_QUADS );
        glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(32.0f, 0.0f, 1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(32.0f, 32.0f, 1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 32.0f, 1.0f);

That's all the relevant information I can think of. Help would be appreciated! :D