Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SDL BOOKS?!

Name: Anonymous 2007-05-19 14:22 ID:31bUIYp/

I want to start up with SDL but i need to order a book about it first. Which books helped you when you were starting out with SDL?

Name: Anonymous 2007-05-19 18:19 ID:EVWdaqOX

Here's the code for a simple window (it also uses GLEW). Next step: learn OpenGL.


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

#include "GL/glew.h"
#include "SDL.h"
//#include "SDL_opengl.h" // -- glew does this
#include "SDL_timer.h"

void show_normal_error (const char *const msg, const bool fatal);
void show_error (const char *const msg, const bool fatal);
void initialize ();
int main (int argc, char *argv[]);
void resize(int w, int h);

void
show_normal_error (const char *const msg, const bool fatal)
{
  fprintf (stderr, "%s\n", msg);
  if (fatal)
    exit (EXIT_FAILURE);
}

void
show_sdl_error (const char *const msg, const bool fatal)
{
  fprintf (stderr, "%s:\n\t%s\n", msg, SDL_GetError ());
  if (fatal)
    exit (EXIT_FAILURE);
}

void
resize (int w, int h)
{
  SDL_Surface * screen = SDL_SetVideoMode( w, h, 0, SDL_OPENGL | SDL_RESIZABLE);
  /* shouldn't free this screen, done by SQL_Quit */
  if ( screen == NULL )
    show_sdl_error("Could not set video mode", true);
}

void
initialize ()
{

  //Initialize SDL:
  if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
    show_sdl_error ("Could not initialize SDL", true);
  else if (atexit (SDL_Quit) != 0 )
    show_normal_error ("Could not register atexit function.", true);

  //Open a window:
  if ( SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) == -1  )
    show_sdl_error("Couldn’t set GL mode", true);
  resize(800,600);

  //Initialize GLEW: (must have a GL context)
  GLenum glew_err = glewInit();
  if ( glew_err != GLEW_OK  ) {
    char errmsg[256] = "";
    snprintf( errmsg, 256, "Error initializing GLEW: %s", glewGetErrorString(glew_err));
    show_normal_error(errmsg, true);
  }

  if (!GLEW_VERSION_1_5) {
    show_normal_error("This program requires support for at least OpenGL 1.5.", true);
  }
}

int
main (int argc, char *argv[])
{
  initialize ();

  SDL_WM_SetCaption("plox", NULL);
 
  SDL_Event event;
  while (SDL_WaitEvent(&event)) {
    switch(event.type) {
      case SDL_VIDEORESIZE:
        resize(event.resize.w, event.resize.h);
        break;
      case SDL_QUIT:
        exit(EXIT_SUCCESS);
        break;
    }
  }
  show_sdl_error("PollEvent failed", true);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List