添加项目文件。

This commit is contained in:
sjm
2024-06-10 01:10:15 +08:00
parent 315df9a039
commit dea8ea58e4
102 changed files with 67007 additions and 0 deletions

100
Demo/main.cpp Normal file
View File

@@ -0,0 +1,100 @@
#define SDL_MAIN_HANDLED
#include <iostream>
#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
#include <SDL2_gfxPrimitives.h>
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
Mix_Init(MIX_INIT_MP3);
TTF_Init();
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
SDL_Window* window = SDL_CreateWindow(u8"<EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
//<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD>񲢴<EFBFBD><F1B2A2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SDL_Surface* suf_img = IMG_Load("avatar.jpg");
SDL_Texture* tex_img = SDL_CreateTextureFromSurface(renderer,suf_img);
TTF_Font* font = TTF_OpenFont("ipix.ttf", 32);
SDL_Color color = { 255,255,255,255 };
SDL_Surface* suf_text = TTF_RenderUTF8_Blended(font, u8"<EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", color);
SDL_Texture* tex_text = SDL_CreateTextureFromSurface(renderer, suf_text);
Mix_Music* music = Mix_LoadMUS("music.mp3");
Mix_FadeInMusic(music, -1, 1500);
int fps = 60;
bool is_quit = false;
SDL_Event event;
SDL_Point pos_cursor = { 0,0 };
SDL_Rect rect_img,rect_text;
Uint64 last_counter = SDL_GetPerformanceCounter();
Uint64 counter_freq = SDL_GetPerformanceFrequency();
rect_img.w = suf_img->w;
rect_img.h = suf_img->h;
rect_text.w = suf_text->w;
rect_text.h = suf_text->h;
while (!is_quit)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
is_quit = true;
}
else if (event.type == SDL_MOUSEMOTION)
{
pos_cursor.x = event.motion.x;
pos_cursor.y = event.motion.y;
}
}
Uint64 current_counter = SDL_GetPerformanceCounter();
double delta = (double)(current_counter - last_counter) / counter_freq;
last_counter = current_counter;
if (delta * 1000 < 1000.0 / 60)
SDL_Delay((Uint32)1000.0 / 60 - delta * 1000);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
rect_img.x = pos_cursor.x;
rect_img.y = pos_cursor.y;
rect_text.x = pos_cursor.x;
rect_text.y = pos_cursor.y;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
//<2F><>Ⱦ<EFBFBD><C8BE>ͼ
SDL_RenderCopy(renderer, tex_img, nullptr, &rect_img);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
filledCircleRGBA(renderer, pos_cursor.x, pos_cursor.y, 50, 255, 0, 0, 125);
SDL_RenderCopy(renderer, tex_text, nullptr, &rect_text);
SDL_RenderPresent(renderer);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>ʾ
}
return 0;
}
/**SDL_FreeSurface<63><65><EFBFBD>ͷŲ<CDB7><C5B2><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA> SDL_Surface<63><65>
SDL_DestroyTexture<72><65>SDL_DestroyRenderer <20><> SDL_DestroyWindow<6F><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD>ʹ<EFBFBD><CDB4>ڡ<EFBFBD>**/