elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Problema con SDL2 + C
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con SDL2 + C  (Leído 5,834 veces)
pathfinder97

Desconectado Desconectado

Mensajes: 1



Ver Perfil
Problema con SDL2 + C
« en: 16 Septiembre 2023, 14:26 pm »

He cambiado de ordenador,y he instalado la última versión de Ubuntu

Distributor ID:   Ubuntu
Description:   Ubuntu 22.04.3 LTS
Release:   22.04
Codename:   jammy


todo para compilar en C/C++ y las librerias de SDL2. El problema es que en el  nuevo ordenador los programas que tenia con SDL2   aunque los vuelva a compilar (la compilación no da ningún error), no se me habre la ventana de SDL2. Los lanzo desde una consola y he puesto sentencias printf para ver por donde va pasando y llega hasta el final!!!

Por ejemplo he compilado este código:
// SDL2 Hello, World!
// This should display a white screen for 2 seconds
// compile with: clang++ main.cpp -o hello_sdl2 -lSDL2
// run with: ./hello_sdl2
#include <SDL2/SDL.h>
#include <stdio.h>

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

int main(int argc, char* args[]) {
  printf("Entrando a programa\n");
  SDL_Window* window = NULL;
  SDL_Surface* screenSurface = NULL;
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError());
    return 1;
  }
  printf("Iniciado SDL\n");
  
  window = SDL_CreateWindow(
             "hello_sdl2",
             SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
             SCREEN_WIDTH, SCREEN_HEIGHT,
             SDL_WINDOW_SHOWN
             );
  if (window == NULL) {
    fprintf(stderr, "could not create window: %s\n", SDL_GetError());
    return 1;
  }
  
  printf("Creada ventana\n");
  screenSurface = SDL_GetWindowSurface(window);
  SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
  SDL_UpdateWindowSurface(window);
  SDL_Delay(2000);
  SDL_DestroyWindow(window);
  SDL_Quit();
  printf("fin\n");
  return 0;
}

Utilizo el makefile:
CXX = g++
PROGRAM = test
SRC = main
OBJECTS = $(SRC).o
# implementation
.SUFFIXES:   .o .cpp
.cpp.o :
   $(CXX) -c `sdl2-config --cflags` -o $@ $<
all:   $(SRC)
$(SRC):   $(OBJECTS)
   $(CXX) -o $(PROGRAM) $(OBJECTS) `sdl2-config --libs` -lm -lSDL2 -lSDL2_image
clean:
   rm -f *.o $(PROGRAM)

Compilo y enlazo:
alex@TITAN:~/Programacion_2023/test_sdl2_mio$ make
g++ -c `sdl2-config --cflags` -o main.o main.cpp
g++ -o test main.o `sdl2-config --libs` -lm -lSDL2 -lSDL2_image
alex@TITAN:~/Programacion_2023/test_sdl2_mio$

Lo ejecuto:

alex@TITAN:~/Programacion_2023/test_sdl2_mio$ ./test
Entrando a programa
Iniciado SDL
Creada ventana
fin
alex@TITAN:~/Programacion_2023/test_sdl2_mio$

Si paso el depurador:

alex@TITAN:~/Programacion_2023/test_sdl2_mio$ gdb test
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...
(gdb) start
Punto de interrupción temporal 1 at 0x12bc: file main.cpp, line 12.
Starting program: /home/alex/Programacion_2023/test_sdl2_mio/test
[Depuración de hilo usando libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 1, main (argc=1, args=0x7fffffffe078) at main.cpp:12
12     printf("Entrando a programa\n");
(gdb) n
Entrando a programa
13     SDL_Window* window = NULL;
(gdb) n
14     SDL_Surface* screenSurface = NULL;
(gdb) n
15     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
(gdb) n
19     printf("Iniciado SDL\n");
(gdb) n
Iniciado SDL
21     window = SDL_CreateWindow(
(gdb) n
27     if (window == NULL) {
(gdb) n
32     printf("Creada ventana\n");
(gdb) n
Creada ventana
33     screenSurface = SDL_GetWindowSurface(window);
(gdb) n
[Nuevo Thread 0x7fffec3ff640 (LWP 12952)]
[Nuevo Thread 0x7fffebbfe640 (LWP 12953)]
[Nuevo Thread 0x7fffeb3fd640 (LWP 12954)]
[Nuevo Thread 0x7fffeabfc640 (LWP 12955)]
[Nuevo Thread 0x7fffe9ffb640 (LWP 12956)]
34     SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
(gdb) n
35     SDL_UpdateWindowSurface(window);
(gdb) n
36     SDL_Delay(2000);
(gdb) n
37     SDL_DestroyWindow(window);
(gdb) n
[Thread 0x7fffe9ffb640 (LWP 12956) terminado]
[Thread 0x7fffeb3fd640 (LWP 12954) terminado]
[Thread 0x7fffeabfc640 (LWP 12955) terminado]
[Thread 0x7fffebbfe640 (LWP 12953) terminado]
[Thread 0x7fffec3ff640 (LWP 12952) terminado]
38     SDL_Quit();
(gdb) n
39     printf("fin\n");
(gdb) n
fin
40     return 0;
(gdb) n
41   }
(gdb) n
__libc_start_call_main (main=main@entry=0x5555555552a9 <main(int, char**)>, argc=argc@entry=1, argv=argv@entry=0x7fffffffe078) at ../sysdeps/nptl/libc_start_call_main.h:74
74   ../sysdeps/nptl/libc_start_call_main.h: No existe el archivo o el directorio.
(gdb) n
[Inferior 1 (process 12914) exited normally]
(gdb)


Si hago programa equivalete con pygame si me abre la ventana con la parte grafica.

¿Alguna idea de que puede estar pasando?


« Última modificación: 16 Septiembre 2023, 17:17 pm por pathfinder97 » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[APORTE] SDL2.0 Tutorial en Vídeos
Programación C/C++
vangodp 5 4,916 Último mensaje 22 Septiembre 2013, 14:09 pm
por vangodp
Hola mundo en SDL2
Programación C/C++
aguaenSDL 6 5,210 Último mensaje 14 Enero 2016, 16:15 pm
por 0xFer
segmentation fault core dumped sdl2 c++
Programación C/C++
misternaim 0 1,716 Último mensaje 22 Marzo 2016, 20:12 pm
por misternaim
Problema con pantalla completa en SDL2(solucionado) « 1 2 3 »
Programación C/C++
jorge245 20 10,906 Último mensaje 11 Mayo 2018, 19:33 pm
por jorge245
[Consulta] SDL2 arreglar movimiento de ventana con click « 1 2 »
Programación C/C++
BloodSharp 13 5,117 Último mensaje 24 Febrero 2019, 21:01 pm
por BloodSharp
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines