Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   SDL en C++ Builder Rad Studio (https://www.clubdelphi.com/foros/showthread.php?t=96855)

navbuoy 26-09-2024 12:19:18

SDL en C++ Builder Rad Studio
 
Es muy facil integrar la SDL en Rad Studio C++ Builder

puedes usar SDL o SDL2 en C++ Builder Rad Studio

solo necesitas convertir el fichero 32 o 64 bit DLL (SDL2.DLL) con Implib a libreria static (archivo LIB) para usarlo en tu Proyecto de Rad Studio

el comando (en linea de comandos del CMD de windows) es "convertir SDL2.DLL, ejecutar “IMPLIB -a -c SDL2.LIB SDL2.DLL” y agregar sdl2.lib al proyecto

he hecho una prueba para ver si funciona y si, funciona perfectamente en Rad Studio C++ Builder 11.3 Alexandria



Código:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <iostream>
#include <algorithm>
#include <SDL.h>
#define SCREEN_WIDTH    800
#define SCREEN_HEIGHT  600

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

        // Initialize SDL
        if(SDL_Init(SDL_INIT_VIDEO) < 0)
        {
          AnsiString cadena = "";
          cadena = sprintf("SDL could not be initialized! - SDL_Error: %d", SDL_GetError());
                ShowMessage(cadena);
                //return 0;
        }
#if defined linux && SDL_VERSION_ATLEAST(2, 0, 8)
        // Disable compositor bypass
        if(!SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"))
        {
                ShowMessage("SDL can not disable compositor bypass!");
                //return 0;
        }
#endif
        // Create window
        SDL_Window *window = SDL_CreateWindow("Basic C++ SDL project",
                                                                                  SDL_WINDOWPOS_UNDEFINED,
                                                                                  SDL_WINDOWPOS_UNDEFINED,
                                                                                  SCREEN_WIDTH, SCREEN_HEIGHT,
                                                                                  SDL_WINDOW_SHOWN);
        if(!window)
        {
          AnsiString cadena = "";

          cadena = sprintf("Window could not be created! - SDL_Error: %d", SDL_GetError());
          ShowMessage(cadena);
        }
        else
        {
                // Create renderer
                SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
                if(!renderer)
                {

                AnsiString cadena = "";

                cadena = sprintf("Renderer could not be created! - SDL_Error: %d", SDL_GetError());
        ShowMessage(cadena);
                }
                else
                {
                        // Declare rect of square
                        SDL_Rect squareRect;
                        // Square dimensions: Half of the min(SCREEN_WIDTH, SCREEN_HEIGHT)
                        squareRect.w = std::min(SCREEN_WIDTH, SCREEN_HEIGHT) / 2;
                        squareRect.h = std::min(SCREEN_WIDTH, SCREEN_HEIGHT) / 2;
                        // Square position: In the middle of the screen
                        squareRect.x = SCREEN_WIDTH / 2 - squareRect.w / 2;
                        squareRect.y = SCREEN_HEIGHT / 2 - squareRect.h / 2;

                        // Event loop exit flag
                        bool quit = false;
                        // Event loop
                        while(!quit)
                        {
                                SDL_Event e;
                                // Wait indefinitely for the next available event
                                SDL_WaitEvent(&e);
                                // User requests quit
                                if(e.type == SDL_QUIT)
                                {
                                        quit = true;
                                }
                                // Initialize renderer color white for the background
                                SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
                                // Clear screen
                                SDL_RenderClear(renderer);
                                // Set renderer color red to draw the square
                                SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
                                // Draw filled square
                                SDL_RenderFillRect(renderer, &squareRect);
                                // Update screen
                                SDL_RenderPresent(renderer);
                        }
                        // Destroy renderer
                        SDL_DestroyRenderer(renderer);
                }
                // Destroy window
                SDL_DestroyWindow(window);
        }
        // Quit SDL
        SDL_Quit();
        //return 0;
}
//---------------------------------------------------------------------------


Neftali [Germán.Estévez] 26-09-2024 15:54:04

Tal vez para los neófitos en el tema, estaría bien explicar qué son SDL y SFML.
Y algún link para que se hagan (o nos hagamos) una idea.

navbuoy 27-09-2024 06:25:08

pues basicamente son unas librerias graficas aunque tambien controlan cosas de sonido y algunas cosas mas

Simple DirectMedia Layer (SDL) es un conjunto de bibliotecas desarrolladas en el lenguaje de programación C que proporcionan funciones básicas para realizar operaciones de dibujo en dos dimensiones, gestión de efectos de sonido y música, además de carga y gestión de imágenes.

https://es.wikipedia.org/wiki/Simple...SDL)%20es%20un

https://gzalo.com/articles/sdl/#:~:t...%20un%20editor

Neftali [Germán.Estévez] 27-09-2024 12:58:21

Cita:

Empezado por navbuoy (Mensaje 557483)
pues basicamente son unas librerias graficas aunque tambien controlan cosas de sonido y algunas cosas mas

Simple DirectMedia Layer (SDL) es un conjunto de bibliotecas desarrolladas en el lenguaje de programación C que proporcionan funciones básicas para realizar operaciones de dibujo en dos dimensiones, gestión de efectos de sonido y música, además de carga y gestión de imágenes.

https://es.wikipedia.org/wiki/Simple...SDL)%20es%20un

https://gzalo.com/articles/sdl/#:~:t...%20un%20editor


^\||/^\||/^\||/^\||/


La franja horaria es GMT +2. Ahora son las 07:20:00.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi