Jump to content

  • Log In with Google      Sign In   
  • Create Account

deathfighter

Member Since 11 Jun 2013
Offline Last Active Jun 12 2013 05:11 PM

Topics I've Started

SDL 2.0 undefined functions and constants problem

11 June 2013 - 04:22 PM

I recently started programming an engine using SDL 1.2.15 and OpenGl. Now i tried to use Nvidia Nsight as shader debugger, but it needs a higher OpenGl version. Since SDL 1.2 doesn't support changing the OpenGl version i simply tried to use SDL 2.

 

I exchanged the library and include paths and changed the linker input to SDL2.lib and SDL2main.lib. (+OpenGL32.lib and glu32.lib) Now the problem is that some methods and constants of SDL are marked as undefined.

 

Just to check i created a new project with the code below with 2 configurations, SDL 1.2 and SDL 2. Like in the other project SDL 1.2 is working and SDL 2 not.

 

#include "SDL.h"
#include "SDL_opengl.h"

#include <stdio.h>
#include <stdlib.h>

#define WIDTH 800
#define HEIGHT 600

static void repaint()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
    SDL_GL_SwapBuffers();
}


static void setup_sdl() 
{
    const SDL_VideoInfo* video;
	int flags = 0;

    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
        
    atexit(SDL_Quit);

    video = SDL_GetVideoInfo( );
    if( video == NULL ) {
        fprintf(stderr, "Couldn't get video information: %s\n", SDL_GetError());
        exit(1);
    }

    /* Set the minimum requirements for the OpenGL window */
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,        8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,      8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,       8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,      8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,      16);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,        32);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1 );

    if( SDL_SetVideoMode( WIDTH, HEIGHT, video->vfmt->BitsPerPixel, SDL_OPENGL ) == 0 ) 
    {
        fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
        exit(1);
    }
}


static void setup_opengl()
{
    float aspect = (float)WIDTH / (float)HEIGHT;
    glViewport(0, 0, WIDTH, HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, aspect, 0.1, 10000.0);
    glMatrixMode(GL_MODELVIEW);
    glClearColor(0, 0, 0, 0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
}

static void main_loop() 
{
    SDL_Event event;

    while (1) 
    {
        while( SDL_PollEvent( &event ) ) 
	{
            switch( event.type ) 
		{
		     case SDL_QUIT: exit (0); break;
                }
        }
        repaint();
    }
}

int main(int argc, char* argv[])
{
    setup_sdl();
    setup_opengl();
    main_loop();
    return 0;
}

 

Undefined items:

SDL_GL_SwapBuffers
SDL_VideoInfo
SDL_GetVideoInfo
SDL_SetVideoMode
SDL_OPENGL 
gluPerspective
SDL_GL_SWAP_CONTROL
SDL_WM_GrabInput
SDL_GRAB_ON
gluErrorString

 

I'm really clueless why some functions and constants are working and some are not.

 

Additional Info: I'm using Visual Studio 2010.


PARTNERS