Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Translating from GLUT to SDL

This topic is 5451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been translating a game I wrote in GLUT to SDL. I wrote a very basic SDL/OpenGL framework, based on a few examples I saw. I'm having two problems. First of all, my GL_QUAD simply isn't appearing. I copy and pasted the actual GL code to make a nice (or not so nice, I'm eventually going to replace it with a picture) background, and its not going to the screen! The other problem is that I'm clearly |'ing SDL_FULLSCREEN and yet it still appears in a window. What am I doing wrong? I compiled it with: g++ main.cpp `sdl-config --libs` -lGL -lGLU -o sdltemplate Here's the code (I admit to using KDevelop, who would actually write in the time like that?):
                          main.cpp  -  description
    begin                : Mon Aug 11 17:38:16 EDT 2003
    copyright            : (C) 2003 by Shalom Naumann


#include <iostream>
#include <cstdlib>
using namespace std;

#include "SDL/SDL.h"
#include <GL/gl.h>
#include <GL/glu.h>

// Prototypes

void sdlexit(int exitNum);
void drawScene();

// The screen

SDL_Surface *surface;

int main()

    // Initializes the SDL API

    if (SDL_Init(SDL_INIT_VIDEO)<0) {
        cerr << "Cannot initialize SDL video. " << SDL_GetError() << ".\n";

    // Gets info about display

    const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
    if (!videoInfo) {
        cerr << "Cannot find information about display device. " << SDL_GetError() << "\n";
    // Sets up double buffering

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    // Defines parameter to next function

    if (videoInfo->blit_hw) videoFlags |= SDL_HWACCEL;

    // Defines the SDL surface as the screen

    surface = SDL_SetVideoMode(1024, 768, 16, videoFlags);
    if (!surface) {
        cerr << "Cannot set video mode. " << SDL_GetError() << "\n";

    // Initializes OpenGL matrices

    glOrtho(0, 1024, 0, 768, -1, 1);

    SDL_Event event;    // Used in the game loop to receive SDL events

    // The game loop

    bool done=false;
    while(!done) {
        // Check for SDL events - inputs and processes

        while(SDL_PollEvent(&event)) {
            switch(event.type) {
            case SDL_KEYDOWN:

        // Outputs


    return 0;

// Cleans up and exits - replaces standard exit funtion 

void sdlexit(int exitNum){
    cout << "This SDL program is now exiting with code " << exitNum << "\n";
    exit(exitNum) ;

// Draws the scene (brilliant comment)

void drawScene() {





    SDL_GL_SwapBuffers();   // Display double buffer on screen

Is there anything utterly wrong with code? If you compile it, does it work? BTW, I'm using SuSE 8.2 with an nVidia (yes, I installed their drivers) GeForce 2. Thanx in advance. [edited by - clum on August 12, 2003 2:01:05 PM]

Share this post

Link to post
Share on other sites
I tried. It didn''t help. I think it starts off as the identity matrix anyway.

Share this post

Link to post
Share on other sites
BTW, I tried it in Windows (on the same machine) and it had the same problems - nothing appeared and it wasn''t full screen (though it did cover the whole screen, it had a title bar).

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
You havn''t set the viewport (or the ''camera'' position)

glViewport(0,0,1024,768); should do the trick.

SDL_FULLSCREEN works for me, but I''m using windows, so it could be a driver issue. perhaps.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!