[SDL] Problem with not using fullscreen.

Chris Rajula superrajula at gmail.com
Mon Mar 5 06:45:41 PST 2007


Hello there!

I have written a small testing-program that uses OpenGL and creates a
window, but I have a small problem, namely that I can't get it not to use
fullscreen.
Using the program to draw a circle or whatever works just fine, but I can't
get it to create a windowed window...

I have the program divided into three separate files. One program-file, one
class-file and one file containing the functions for the class.
I appreciate any help.

Thank you.

/Chris

Here we go:
window.h:
#ifndef _draw_h
#define _draw_h

class window{
        private:
                int height;
                int width;
                int depth;
                bool debug;
                bool fullscreen;
        public:
                window();
                window(int w, int h, int d, bool fs);
                void SDLInit();
                void Event();
                ~window();
};

#endif

window.cpp:
#ifdef WIN32
#include <windows.h>
#endif

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

window::window(){
        debug = 1;
        width = 640;
        height = 480;
        depth = 32;
        fullscreen = false;
        if(debug == 1)
                std::cout << "Height, width, and depth specified.\n";
}

window::window(int w,int h,int d,bool fs){
        if(fs == true) fullscreen = true;
        else fullscreen = false;
        if(h == 0) h = 1;
        if(w == 0) w = 1;
        if(d == 0) d = 32;
        width = w;
        height = h;
        depth = d;
        if(debug == 1)
                std::cout << "Height, width, and depth specifically
specified.\n";
}


void window::SDLInit(){
        int error;
        // Just initialize everything and check for errors. Keep it simple,
stupid. FIXME Check the error flag.
        error = SDL_Init(SDL_INIT_EVERYTHING);
        // std::cout << SDL_GetError();
        // I keep getting "Failed loading DPMSDisable: /usr/lib/libX11.so.6:
undefined symbol" here.
        // It has something to do with SDLinitializing video, but I don't
think it's a problem.

        // Here we set the different attributes for the drawing context.
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);    // Double buffering.
(Draw on offscreen buffer, then move to screen.)
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth);  // Depth of the
buffer.
        // Be sure to allocate space for the different colors to 8 bits,
since we use a depth of 32 bits. FIXME (8/colour for 32bit depth!)
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);                // Red
colour.
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);      // Green colour.
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);               // Blue
colour.
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);      // Transparency.
        // Creating an SDL surface.
        Uint32 flags;   // Used for choosing how the drawing context should
act.
        if(fullscreen == true) flags = SDL_OPENGL | SDL_FULLSCREEN;
        else flags = SDL_OPENGL;
        SDL_Surface* drawContext;
        // Create the OpenGL draw context.
        drawContext = SDL_SetVideoMode(width,height,depth,flags);
}

void window::Event(){
        SDL_Event event;
        bool exit = false;
        while((!exit) && (SDL_WaitEvent(&event))) {
                switch(event.type) {
                        case SDL_KEYDOWN:
                                exit = true;
                        break;
                        case SDL_MOUSEBUTTONDOWN:
                                exit = true;
                        break;
                }
        }
}

window::~window(){
        SDL_Quit();
}

test.cpp:
#include <iostream>
#include "window.h"

int main(int argc, char *argv[]){
        bool fs = true;
        window window;
        //window window(100,100,32,fs);
        window.SDLInit();
        // The main function should here call some different stuff.
        // Preferences();
        // It should enable or disable antialiasing and such, and read
values from a file of user preferences.
        // It should also call a specific first-run-function to set the
initial values for the user.
        window.Event();
        return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070305/deb73c87/attachment-0001.html 


More information about the SDL mailing list