elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 00:54  


Tema destacado: Entra al canal IRC oficial de #elhacker.net

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse)
| | |-+  Duda SDL_init()
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Duda SDL_init()  (Leído 464 veces)
Ferno

Desconectado Desconectado

Mensajes: 282


Ver Perfil
Duda SDL_init()
« en: 4 Diciembre 2011, 03:20 »

Gente, estoy con algo bastante curioso (o tan tonto que no lo veo :P).
Resulta que estoy trabajando con la librería SDL, en Eclipse. Tengo 2 proyectos diferentes, con un archivo source cada uno. Aclaro que ambos proyectos están en el mismo directorio y tienen exactamente las mismas propiedades.

Ahora bien, en un source tengo este código:


Código
#include <stdio.h>
#include <SDL/SDL.h>
 
int main (int argc, char* argv[])
{
SDL_Surface* screen;
SDL_Surface* surface;
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
 
if(SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0)
{
printf("No se puede inicializar SDL: %s\n",SDL_GetError());
exit(1);
}
 
screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE | SDL_DOUBLEBUF);
if ((screen == NULL))
{
fprintf(stderr, "No se puede establecer el modo video 640x480: %s \n",SDL_GetError());
exit(1);
}
 
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,640,480,32,rmask,gmask,bmask,amask);
if ((surface == NULL))
{
fprintf(stderr,"Error al crear pantalla %s \n",SDL_GetError());
exit(1);
}
 
 
 
printf("Está todo más que bien\n");
atexit(SDL_Quit);
return 0;
}
 

Algo muy simple en SDL, recién para arrancar. Compila, lo corro, y funciona de pelos.
Ahora bien en el otro source tengo este otro código:


Código
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
 
int main (int argc, char* argv[])
{
SDL_Surface *screen, *image;
Uint32 rmask, bmask, gmask, amask;
SDL_Rect dest; /*Destiny of the image*/
SDL_Event event;
int done = 0;
 
atexit(SDL_Quit);
 
/*INIT SDL*/
if (SDL_Init(SDL_INIT_VIDEO) < 0);
{
printf("No se pudo inicializar SDL %s \n", SDL_GetError());
exit(1);
}
 
/*ACTIVATE VIDEO MODE*/
screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE);
if ((screen == NULL))
{
printf("No se pude inicializar el modo gráfico %s \n",SDL_GetError());
exit(1);
}
 
/*UPLOAD GRAPHIC*/
image = SDL_LoadBMP("Ruta.bmp");
if (image == NULL)
{
printf("No se pudo cargar gráfico %s \n",SDL_GetError());
exit(1);
}
 
/*Defining destiny of the image*/
dest.x = 100;
dest.y = 100;
dest.w = image->w;
dest.h = image->w;
SDL_BlitSurface(image,NULL,screen,&dest);
 
/*Show Screen*/
SDL_Flip(screen);
 
/*Free Surface*/
SDL_FreeSurface(image);
 
/*Waiting for the user to press to quit*/
while (done == 0)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
done = 1;
}
}
 
/*FINISH SDL*/
return 0;
}
 

También compila perfecto. El problema es que al correrlo, me da un error en el SDL_Init. Es decir, entra al if del SDL_Init.
Lo curioso es que limpio esa parte del código, es decir, no inicializo el SDL, y funciona perfectamente el programa. Carga la ventana con la respectiva imágen.

No entiendo, ¿Alguien sabe qué está ocurriendo?


En línea
Ferno

Desconectado Desconectado

Mensajes: 282


Ver Perfil
Re: Duda SDL_init()
« Respuesta #1 en: 7 Diciembre 2011, 19:31 »

Pfff, soy lo PEOR!!
Error: Si se fijan tengo un ";" luego del if del SDL_Init del segundo código.

Estos errores de tipeo me molestan demasiado :P


En línea
Littlehorse
All the world's a stage
Moderador
***
Desconectado Desconectado

Mensajes: 2.710


Nie Dam Sie


Ver Perfil WWW
Re: Duda SDL_init()
« Respuesta #2 en: 9 Diciembre 2011, 01:04 »

Pfff, soy lo PEOR!!
Error: Si se fijan tengo un ";" luego del if del SDL_Init del segundo código.

Estos errores de tipeo me molestan demasiado :P

Cosas que pasan en el fragor de la batalla contra el código  ;D
En línea

An expert is a man who has made all the mistakes which can be made, in a very narrow field.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[duda] liberar memoria fisica [/duda]
GNU/Linux
k a t z 1 1,562 Último mensaje 30 Diciembre 2006, 00:38
por cthulhufhtagn
OTRA DUDA DE LOS MALDITOS Iframes. Duda HTML. 20-5
Desarrollo Web
‭lipman 7 2,907 Último mensaje 21 Mayo 2007, 09:27
por dominioswww
Pequeña duda con un comando batch (NUEVA DUDA RELACIONADA)
Scripting
revenge1252 9 2,503 Último mensaje 13 Febrero 2008, 21:41
por revenge1252
Duda batch y ademas duda del foro
Hacking Básico
relom 4 1,302 Último mensaje 9 Marzo 2008, 06:32
por Leo Gutiérrez.
<duda>Polimorfismo en C</duda>
Análisis y Diseño de Malware
marlochack 8 3,132 Último mensaje 2 Febrero 2010, 01:23
por [L]ord [R]NA
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines