2
6
2014
5

SDL学习笔记1:SDL的Hello World!

参照国内最容易搜到的中文教程,一些讲解就在注释里了

 

#include "SDL.h"
#include <iostream>
#include <Windows.h>

int main(int argc,char**argv)
{
	// 初始化SDL的“一切”,不成功main返回-1,本例均如此
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
	{
		std::cout << SDL_GetError() << std::endl;
		return 1;
	}

	// 创建窗口指针
	SDL_Window *win = nullptr;
	win = SDL_CreateWindow("First SDL Program!!",100,100,800,600,SDL_WINDOW_SHOWN);
	if (win == nullptr)
	{
		std::cout << SDL_GetError() << std::endl;
		return 1;
	}

	// 创建SDL Renderer(渲染器)指针
	SDL_Renderer *ren = nullptr;
	// 参数分别为:指定窗口,自动选择显卡驱动,使用图形加速|以显示器频率同步
	ren = SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == nullptr)
	{
		std::cout << SDL_GetError() << std::endl;
		return 1;
	}

	// 创建SDL_Surface,用于载入图像
	SDL_Surface *bmp = nullptr;
	bmp = SDL_LoadBMP("image.bmp");
	if (bmp == nullptr)
	{
		std::cout << SDL_GetError() << std::endl;
		return -1;
	}

	// 创建SDL_Texture(材质)
	SDL_Texture *tex = nullptr;
	tex = SDL_CreateTextureFromSurface(ren,bmp);
	SDL_FreeSurface(bmp);

	// 清空屏幕,绘图,刷新屏幕
	SDL_RenderClear(ren);
	SDL_RenderCopy(ren,tex,NULL,NULL);
	SDL_RenderPresent(ren);

	// 延迟4秒后关闭窗口
	SDL_Delay(4000);

	// 释放内存
	SDL_DestroyTexture(tex);
	SDL_DestroyRenderer(ren);
	SDL_DestroyWindow(win);

	// 退出
	SDL_Quit();

	return 0;
}

补充:

窗口标题无法显示中文。

Category: SDL学习笔记 | Tags: | Read Count: 5746
Avatar_small
Amber McMeckan 说:
2018年11月29日 11:39

A free quantum of the products is launched for the goodness and all apparent roles for the humans. The right use of the term and ukessays is vital for the humans. The reflection is inquired for the flow of the terms for the humans in various offers for the partners in the field.

Avatar_small
deep cleaning servic 说:
2019年10月12日 20:00

We offer best cleansing services within abu dhabi, we now have professional cleansing staff within our company, we usually give much more importance as well as preference to the customers, we now have thousands associated with happy clients in abu dhabi, we always play the role of best cleansing services organization in abu dhabi and throughout UAE.

Avatar_small
maid services dubai 说:
2021年9月13日 17:34

We have now a workforce of professionals who definitely are well trained in the field of housekeeping. There're experienced in addition to efficient in each and every house drag. You can certainly hire some sort of part-time housemaid with Dubai or based on the daily chores decide on full-time maids in Dubai. As a result of us, you're free to unlock many cleaning products and services.

Avatar_small
live in maids dubai 说:
2021年9月27日 17:21

Supplying your washing services to be able to high targeted traffic stores which usually require everyday cleaning can cause an also higher amount, consistent earnings stream. Going door-to-door inside the shopping district can cause clients, but will probably be time-intensive. In the event you hire any commissioned salesperson to be effective on developing this business it can easily limit the immediate expenditure because of this legwork and be extremely profitable inside the long-run.

Avatar_small
monthly cleaning ser 说:
2023年8月26日 17:07

Top quality is relative to the value. If the consumer believes the painting appraisal is also low chances are they might believe the color contractor will be either lower balling, inexperienced or perhaps cutting charges by cheapening the work for some reason or one more. The customer will likely then believe they are not getting the best value from in which paint estimate and definately will not yet from in which contractor even when the price is leaner.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com