Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 26-09-2024
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Poder: 2
navbuoy Va por buen camino
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;
}
//---------------------------------------------------------------------------
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
consultar a API ChatGPT con REST en C++ Builder Rad Studio 12 navbuoy C++ Builder 12 13-03-2024 23:23:00
CSFML en Rad Studio 10.0 Seattle (o en C++ Builder en general) Snaked C++ Builder 3 24-11-2016 04:40:32
[DANYSOFT] Novedades Delphi, C++Builder y RAD Studio XE8 neftali2 Noticias 0 07-04-2015 11:30:39
Aplicación C++builder 6 a Visual studio 2005 Julian Uribe C++ Builder 0 23-02-2010 15:57:01


La franja horaria es GMT +2. Ahora son las 03:11:35.


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
Copyright 1996-2007 Club Delphi