SDL - Pantalla en negro

Tratamos sobre el manejo de APIs frecuentemente utilizadas en el desarrollo de videojuegos, como SDL, pygame o SFML.

SDL - Pantalla en negro

Notapor metalalucard » Lun Sep 05, 2011 11:32 pm

Estoy empezando un tutorial de SDL y en un ejemplo lo pase a c++ dado que esta hecho en C , total que lo compilo y no me manda errores, pero al ejecutarlo se queda la pantalla de comandos en negro y no sale nada, aqui dejo el codigo que hice:

Archivos de cabecera: sdl_videoinfo.h
//Listado: sdl_videoinfo.h
//Funcion que muestra la compatibilidad del sistema con las tecnologias
//utilizadas por la SDL

#ifndef _SDL_VIDEOINFO_
#define _SDL_VIDEOINFO_

//Precondicion: El subsistema de video SDL debe estar activado.
//Postcondicion: Obtiene informacion de las estructuras de SDL video info
//y la muestra en pantalla

void sdl_videoinfo(void);

#endif


compatibilidad_video.h
//Listado: compatibilidad_video.h

#ifndef _COMPATIBILIDAD_SDL_
#define _COMPATIBILIDAD_SDL_

//Precondicion: Subsistema de video de SDL Activo.
//Postcondicion: Realiza comprobaciones de compatibilidad de
//SDL con varias opciones de inicializacion.

void compatibilidad_video_sdl(int w, int h, int bpp);

#endif


Los archivos cpp
compatibilidad_video.cpp
//Listado: compatibilidad_video.cpp
//Comprueba la compatibilidad del sistema con los modos de videos de libsdl
//mediante el metodo ensayo-error

#include <iostream>
#include <SDL/SDL.h>
#include "compatibilidad_video.h"

using namespace std;

void compatibilidad_video_sdl(int w, int h, int bpp)
{
//Nuestro Rectangulo grafico con la informacion de video a mostrar
SDL_Surface *pantalla;

//Vamos a probar los diferentes parametros de SetVideoMode
//Almacenando la superficie en memoria principal a w x h x bpp
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE);

if(pantalla == NULL){
cout << "SDL_SWSURFACE" << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_SWSURFACE " << w << " X " << h << " X " << bpp << endl;
}

//Almacenando la suerficie en memoria de video a w x h x bpp
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_HWSURFACE);

if(pantalla == NULL){
cout << "SDL_HWSURFACE " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_HWSURFACE " << w << " X " << h << " X " << bpp << endl;

//Es compatible con el doble buffer? Solo con HWSURFACE
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_HWSURFACE | SDL_DOUBLEBUF);

if(pantalla == NULL){
cout << "SDL_DOUBLEBUF " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_DOUBLEBUF " << w << " X " << h << " X " << bpp << endl;
}
}

// Blit Asincrono para mejorar rendimiento en maquinas multiprocesador
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_ASYNCBLIT);

if(pantalla == NULL){
cout << "SDL_ASYNCBLIT " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_ASYNCBLIT " << w << " X " << h << " X " << bpp << endl;
}

//Forzamos los bpp en modo ventana
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_ANYFORMAT);

if(pantalla == NULL){
cout << "SDL_ANYFORMAT " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_ANYFORMAT " << w << " X " << h << " X " << bpp << endl;
}

//Acceso exclusivo a la paleta de color
pantalla = SDL_SetVideoMode(w, h, bpp ,SDL_HWPALETTE);

if(pantalla == NULL){
cout << "SDL_HWPALETTE " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_HWPALETTE " << w << " X " << h << " X " << bpp << endl;
}

//Modo a pantalla completa
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_FULLSCREEN);

if(pantalla == NULL){
cout << "SDL_FULLSCREEN " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_FULLSCREEN " << w << " X " << h << " X " << bpp << endl;
}

//Crear un contexto OpenGL en la superficie
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_OPENGL);

if(pantalla == NULL){
cout << "SDL_OPENGL " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_OPENGL " << w << " X " << h << " X " << bpp << endl;
}

//Crear un contexto OpenGl en la superficie y permitir renderizado OpenGl
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_OPENGLBLIT);

if(pantalla == NULL){
cout << "SDL_OPENGLBLIT " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_OPENGLBLIT " << w << " X " << h << " X " << bpp << endl;
}

//Permite que la superficie principal pueda cambiarsele el tamaño
pantalla = SDL_SetVideoMode(w, h, bpp, SDL_RESIZABLE);

if(pantalla == NULL){
cout << "SDL_RESIZABLE " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_RESIZABLE " << w << " X " << h << " X " << bpp << endl;
}

pantalla = SDL_SetVideoMode(w, h, bpp, SDL_NOFRAME);

if(pantalla == NULL){
cout << "SDL_NOFRAME " << w << " X " << h << " X " << bpp << endl;
cout << " no compatible. Error: " << SDL_GetError() << " \n" << endl;}
else{
cout << "Compatible con SDL_NOFRAME " << w << " X " << h << " X " << bpp << endl;
}
}


sdl_videoinfo.cpp
//Listado: sdl_videoinfo
//Implementacion de la funcion sdl_videoinfo()

#include <iostream>
#include <SDL/SDL.h>
#include "sdl_videoinfo.h"
#include "compatibilidad_video.h"

using namespace std;

void sdl_videoinfo(void)
{
const SDL_VideoInfo *propiedades;
SDL_Surface *pantalla;
SDL_Rect **modos;

//Variables auxiliares
char driver[20];
int maxlen = 20;
int i = 0;

//Obtenemos la informacion del sistema de video
propiedades = SDL_GetVideoInfo();
if(propiedades == NULL){
cout << cerr << "No se pudo obtener la informacion " << SDL_GetError() << endl;
exit(1);}

//Obtenermos los modos de video disponibles
modos = SDL_ListModes(NULL,SDL_HWSURFACE);

cout << "\n\n == MODOS DE VIDEO DISPONIBLES == \n" << endl;

//Comprobamos que metodos estan disponibles
if(modos == (SDL_Rect **)0){
cout << "No existen modos disponibles \n" << endl;}
else if(modos == (SDL_Rect **)-1){
cout << "Todos los modos disponibles \n" << endl;}
else{
cout << "Lista de modos disponibles \n" << endl;
for(i = 0;modos[i]; i++){
cout << modos[i]->w << " X " << modos[i]->h << endl;}
}

//Comprobamos que el modo a seleccionar sea compatible
if(SDL_VideoModeOK(640, 480, 24, SDL_SWSURFACE) == 0){
cout << cerr << "Modo no soportado: " << SDL_GetError() << endl;
exit(1);}

//Una vez comprobado establecemos el modo de video
pantalla = SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE);
if(pantalla == NULL){
cout << "SDL_SWSURFACE 640X480X24 no compatible. Error: " << SDL_GetError() << endl;}

//Obtenemos informacion del driver de video
cout << "\n\n == INFORMACION DRIVER VIDEO == \n" << endl;
SDL_VideoDriverName(driver, maxlen);

if(driver == NULL){
cout << cerr << "No se puede obtener nombre del driver de video \n" << endl;
exit(1);}
cout << "Driver: " << driver << endl;

//Obtenermos informacion sobre las capacidades de nuestro
//sistema respecto a SDL
cout << "\n == INFORMACION SDL_INFO == \n\n" << endl;
if(propiedades->hw_available == 1){
cout << "HW Compatible \n" << endl;}
else{
cout << "HW NO Compatible \n" << endl;}

if(propiedades->hw_available == 1){
cout << "Hay un manejador de ventanas disponible \n" << endl;}
else{
cout << "NO Hay un manejador de ventanas disponible \n" << endl;}

if(propiedades->blit_hw == 1){
cout << "El blitting hardware - hardware esta acelerado \n" << endl;}
else{
cout << "El blitting hardware - hardware NO esta acelerado \n" << endl;}

if(propiedades->blit_hw_CC == 1){
cout << "El blitting con transparencias hardware - hardware esta acelerado \n" << endl;}
else{
cout << "El blitting con transparencias hardware - hardware NO esta acelerado \n" << endl;}

if(propiedades->blit_sw == 1){
cout << "El blitting software - hardware esta acelerado \n" << endl;}
else{
cout << "El blitting software - hardware NO esta acelerado \n" << endl;}

if(propiedades->blit_sw_CC == 1){
cout << "El blitting software - hardware con transparencias esta acelerado \n" << endl;}
else{
cout << "El blitting software - hardware con transparencias NO esta acelerado \n" << endl;}

if(propiedades->blit_sw_A == 1){
cout << "El blitting software - hardware con alpha esta acelerado \n" << endl;}
else{
cout << "El blitting software - hardware con alpha NO esta acelerado \n" << endl;}

if(propiedades->blit_fill == 1){
cout << "El rellenado de color esta acelerado \n" << endl;}
else{
cout << "El rellenado de color NO esta acelerado \n" << endl;}

cout << "La memoria de video tiene " << (float) propiedades->video_mem << "MB \n" << endl;
}

void datos_configuracion(int *w, int *h, int *bpp);

int main(int argc, char *argv[])
{
int opcion;
int h, w, bpp;
atexit(SDL_Quit);

do{
//Iniciamos SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0){
cout << cerr << "No se pudo iniciar SDL: " << SDL_GetError() << endl;
exit(1);}

//Menu
cout << "\n 1.- Compatibilidad Video SDL \n" << endl;
cout << " 2.- Informacion SDL_VideoInfo \n" << endl;
cout << " 3.- Salir \n" << endl;
cout << "Elija una opcion: " << endl;
cin >> opcion;

switch(opcion){
case 1:
datos_configuracion(&w, &h, &bpp);
compatibilidad_video_sdl(w, h, bpp);
SDL_Quit();
break;

case 2:
sdl_videoinfo();
SDL_Quit();
break;

case 3:
SDL_Quit();
break;

default:
cout << "\n Opcion no valida \n" << endl;
}}while(opcion != 3);
return 0;
}

//Funcion para inicializar los datos para comproblar la compatibilidad

void datos_configuracion(int *w, int *h, int *bpp){

cout << "\nIntroduce la anchira en pixeles de la pantalla: " << endl;
cin >> *w;

cout << "\nIntroduce la altura en pixeles de la pantalla: " << endl;
cin >> *h;

cout << "Introduce la profundidad de color: " << endl;
cin >> *bpp;

cout << "\n" << endl;
}


mi archivo main
//Listado: main.c
//Programa de prueba, compatibilidad
//del sistema e informacion SDL video_info

#include <iostream>
#include <SDL/SDL.h>
#include "compatibilidad_video.h"
#include "sdl_videoinfo.h"


using namespace std;

void datos_configuracion(int *w, int *h, int *bpp);

int main(int argc, char *argv[])
{
int opcion;
int h, w, bpp;
atexit(SDL_Quit);

do{
//Iniciamos SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0){
cout << cerr << "No se pudo iniciar SDL: " << SDL_GetError() << endl;
exit(1);}
//Menu
cout << "\n 1.- Compatibilidad Video SDL \n" << endl;
cout << " 2.- Informacion SDL_VideoInfo \n" << endl;
cout << " 3.- Salir \n" << endl;
cout << "Elija una opcion: " << endl;
cin >> opcion;

switch(opcion){
case 1:
datos_configuracion(&w, &h, &bpp);
compatibilidad_video_sdl(w, h, bpp);
SDL_Quit();
break;

case 2:
sdl_videoinfo();
SDL_Quit();
break;

case 3:
SDL_Quit();
break;

default:
cout << "\n Opcion no valida \n" << endl;
}}while(opcion != 3);
return 0;
}

//Funcion para inicializar los datos para comproblar la compatibilidad

void datos_configuracion(int *w, int *h, int *bpp){

cout << "\nIntroduce la anchira en pixeles de la pantalla: " << endl;
cin >> *w;

cout << "\nIntroduce la altura en pixeles de la pantalla: " << endl;
cin >> *h;

cout << "Introduce la profundidad de color: " << endl;
cin >> *bpp;

cout << "\n" << endl;
}


Estare muy agradecido si alguien tiene alguna respuesta.
metalalucard
 
Mensajes: 1
Registrado: Lun Sep 05, 2011 11:17 pm

Volver a Sobre las bibliotecas multimedia

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados