/** * SDL2暴力缩放用作屏幕分辨率适配 * 1:以逻辑分辨率绘图,比如240*480 * 2:以物理分辨率显示(在电脑上是窗口分辨率;在安卓上是屏幕分辨率) * 3:要做ui的话需要 鼠标或者触摸点的坐标 换算到 逻辑坐标 */ #include <SDL2/SDL.h> int main(int argc,char *argv[]) { //初始化sdl SDL_Init(SDL_INIT_VIDEO); //创建窗口和物理分辨率 SDL_Window *windows1 = SDL_CreateWindow("render",100,100,480,800,SDL_WINDOW_SHOWN); //创建基于窗口的渲染器 SDL_Renderer *windows1_render = SDL_CreateRenderer(windows1,-1,SDL_RENDERER_ACCELERATED); //设置渲染器的逻辑分辨率 SDL_RenderSetLogicalSize(windows1_render,240,400); //设置渲染器绘图颜色 SDL_SetRenderDrawColor(windows1_render,255,0,0,200); //渲染器绘制线段 SDL_RenderDrawLine(windows1_render,0,0,240,400); //在窗口上呈现渲染器 SDL_RenderPresent(windows1_render); //延时2s SDL_Delay(3000); //销毁渲染器 SDL_DestroyRenderer(windows1_render); //销毁窗口 SDL_DestroyWindow(windows1); //退出sdl SDL_Quit(); //结束程序 return 0; }
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。