Sign in to follow this  

Listmodes fprintf

Recommended Posts

hi i am trying to get a list of available modes, at the moment this (from another example) doesn't block building, but how do i get the info to print the console i presume? nothing comes up... SDL_Rect **modes;int i; modes = SDL_ListModes(NULL, SDL_HWSURFACE|SDL_FULLSCREEN); for(i=0; modes[i]; ++i) { fprintf("%ix%i\n",modes[i]->w,modes[i]->h); } would i have to change at NULL? nothing seems to print to console....not even hello world???

Share this post

Link to post
Share on other sites
oh, jeez,ok i am going to try...

ok that still hasn't worked, i did try printf earlier, but adding fprintf(stdout,...still nada in console,mmm don,t want to bother, so will come back later after i go read up more.....

i add the other lines after

bpp = info->vfmt->BitsPerPixel;

which seems reasonable.

Share this post

Link to post
Share on other sites
ok i needed to learn a bit more c, duh, i found the stdout file in my debug folder with all the relevant info, great thanks for the help.

Share this post

Link to post
Share on other sites
could i ask one more question, perhaps rather silly, but how do you position the window at the top-left corner of the screen with SDL?

i am still getting used to SDL after moving from GLUT, there were a couple of things i could do in GLUT that i can't or don't know how to in SDL(or if SDL allows them),

some are


are these possibilities in SDL??

Share this post

Link to post
Share on other sites
You can get the screen width and height like so:

SDL_Surface *video = SDL_GetVideoSurface();
// use the "w" and "h" members of the SDL_Surface structure
// note: make sure video pointer isn't NULL!
int width = video->w, height = video->h;

There is no easy way to set the position of the window. There are two alternatives
0) set the position before creating the window via environmental variables
1) use platform specific code

For 0), you can use the SDL environment variables:

SDL_VIDEO_CENTERED set to any value to center the window
SDL_VIDEO_WINDOW_POS set to "x,y" or "center"

I won't go into 1, except to point you at this function.

Share this post

Link to post
Share on other sites
great thanks man, i was just reading a thread on setting up using environmental vars and platform specific, it seems platform specific might be an easier one, at least from a win32 glance, i need to create a pointer to the specific os window type struct in SDL_syswm, and adjust it there, at least this way i can get it to work on my XP machine for now, and then later(or soon i hope) i will set up a dual boot for linux and work on it from that side, but enough of that, thanks for the get win width/height help, hopefully this is what i think it is,

basically what i want to do is, just before my app closes i want to write the window height/width to a file that gets used on next open, most times this will be maximised-i guess and guessings just that-and on next open the window will open nicely, or not, but that is what it would've done anyhow.

Share this post

Link to post
Share on other sites
after looking through another thread...

i managed to get it working, i also used GetSystemMetrics to get the fullscreen proportions, this way i can make a fullscreen taskbar window which is positioned correctly, only for win32 though, but i am definitely adding it to my to do projects for at least a linux environment(i cant afford a mac),

thanks so much for the help....
here is the sample cod if you'r interested....not sure how i add code correctly in these forums

#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
/*this will include both gl and glu and windows.h*/
#include <SDL/SDL_opengl.h>
#include <stdio.h>
#include <stdlib.h>

static void checks();
static void quits(int status);
int wide;
int high;


static void checks()
if (SDL_Init(SDL_INIT_VIDEO) < 0)
printf("Error with video format: %s",SDL_GetError());



static void quits(status)





int main (int argc, char *argv[])
SDL_Event event;
float theta = 0.0f;


wide = 500;
high = 500;

#ifdef WIN32
SDL_SysWMinfo i;

SDL_VERSION( &i.version );

if (!SDL_GetWMInfo(&i)) {
fprintf(stderr, "Failed to get WM Info!\n");

HWND hwnd = i.window;

wide = (GetSystemMetrics( SM_CXSCREEN ))-1;

high = (GetSystemMetrics( SM_CYSCREEN ))-40;

SetWindowPos(hwnd, HWND_TOP, 0, 0, wide, high, SWP_DRAWFRAME);


SDL_Surface *mywin;


//set up sdl_gl attributes before

mywin = SDL_SetVideoMode(wide, high, 0, SDL_OPENGL |SDL_SWSURFACE);

glViewport(0, 0, 600, 300);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

int done;
for(done = 0; !done;){

glRotatef(theta, 0.0f, 0.0f, 1.0f);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.87f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(-0.87f, -0.5f);

theta += .5f;
if(event.key.keysym.sym == SDLK_ESCAPE)
done = 1;

//setup gl win here

//run other here


//never reached!!
return 0;


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this