本文整理汇总了C++中SDL_CreateWindowAndRenderer函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_CreateWindowAndRenderer函数的具体用法?C++ SDL_CreateWindowAndRenderer怎么用?C++ SDL_CreateWindowAndRenderer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_CreateWindowAndRenderer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void SDLWindow::Initialize()
{
assert(((start_location.w > 0 && start_location.h > 0) || start_location.w == start_location.h),
"If a special resolution modifier is to be used, then both length and width must be equal.");
if (start_location == USE_CURRENT_RESOLUTION)
{
SDL_DisplayMode display_mode;
assert((SDL_GetCurrentDisplayMode(DISPLAY_NUMBER, &display_mode) == 0), SDL_GetError());
start_location.w = (double)display_mode.w;
start_location.h = (double)display_mode.h;
}
if (fullscreen)
{
SDL_CreateWindowAndRenderer(0, 0,
(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS),
&window, &write_to);
// Scale so the user's code doesn't know the difference.
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother.
SDL_RenderSetLogicalSize(write_to, GfxRound(start_location.w), GfxRound(start_location.h));
}
else
{
SDL_CreateWindowAndRenderer(GfxRound(start_location.w), GfxRound(start_location.h), 0, &window, &write_to);
}
SDL_SetWindowTitle(this->window, this->title);
SDL_SetRenderDrawColor(write_to, fill.r, fill.g, fill.b, fill.a);
SDL_RenderClear(write_to);
SDL_RenderPresent(write_to);
}
示例2: SDL_GetError
int Game::initSystems()
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
cerr << "Problem while initializing SDL" << endl;
return -1;
}
#ifndef WIN32
if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN, &m_pWindow, &m_pRenderer) < 0)
#else
screen_w = 640;
screen_h = 480;
if (SDL_CreateWindowAndRenderer(screen_w, screen_h, 0, &m_pWindow, &m_pRenderer) < 0)
#endif
{
std::cout << "SDL_CreateWindowAndRenderer Error: " << SDL_GetError() << std::endl;
return 0;
}
SDL_GetWindowSize(m_pWindow, &screen_w, &screen_h);
screen = SDL_CreateRGBSurface(0, screen_w, screen_h, 32,
0,
0,
0,
0);
if (screen == 0)
{
std::cout << "SDL_CreateRGBSurface Error: " << SDL_GetError() << std::endl;
return false;
}
m_pScreenTexture = SDL_CreateTexture(m_pRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
screen_w, screen_h);
if (m_pScreenTexture == 0)
{
std::cout << "SDL_CreateTexture Error: " << SDL_GetError() << std::endl;
return -1;
}
if (TTF_Init() < 0) {
cerr << "Problem initializing SDL_ttf" << endl;
return -1;
}
if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 4096) < 0) {
cerr << "Problem initializing SDL_mixer" << endl;
return -1;
}
Mix_Init(MIX_INIT_MP3);
return 0;
}
示例3: Init_Window
void Init_Window(unsigned int Height, unsigned Width, std::string Title)
{
Window_Info.Height = Height;
Window_Info.Width = Width;
Window_Info.Title = Title;
Window_Info.Ren = nullptr;
Window_Info.Win = nullptr;
Window_Info.Sur = nullptr;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
throw std::runtime_error("SDL Init Failed!!");
#ifdef SDL_EX_TTF
if (TTF_Init() < 0)
throw std::runtime_error("TTF Init Failed!!");
#endif
if (SDL_CreateWindowAndRenderer(Window_Info.Width, Window_Info.Height, SDL_WINDOW_SHOWN, &Window_Info.Win, &Window_Info.Ren) < 0)
{
std::cout << "Fuck!!" << SDL_GetError() << std::endl;
}
std::cout << "Fuck!!" << SDL_GetError() << std::endl;
SDL_SetWindowTitle(Window_Info.Win, Title.c_str());
Window_Info.Sur = SDL_GetWindowSurface(Window_Info.Win);
SetSDLWindowIcon(Window_Info.Win);
if (Window_Info.Sur == nullptr)
throw std::runtime_error("Failed to Get Window Surface!!");
}
示例4: main
int main(int argc, char *argv[])
{
#pragma unused(argc, argv)
SDL_Window *window;
SDL_Renderer *renderer;
int done = 0;
SDL_Event event;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_ERROR(SDL_Init);
return 1;
}
if (SDL_CreateWindowAndRenderer(200, 200, 0, &window, &renderer) == -1) {
SDL_ERROR(SDL_SetVideoMode);
SDL_Quit();
return 1;
}
while (!done) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT ||
(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_LGUI || event.key.keysym.mod == KMOD_RGUI))) {
done = !0;
}
}
SDL_Delay(0);
}
SDL_Delay(500);
SDL_Quit();
return 0;
}
示例5: srand
void mGraphics::initSDL(){
srand((int)time(0));
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_CreateWindowAndRenderer(W, H, SDL_WINDOW_OPENGL, &(window), &(renderer));
SDL_GetRendererInfo(renderer, &info);
/*TODO: Check that we have OpenGL */
if ((info.flags & SDL_RENDERER_ACCELERATED) == 0 ||
(info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
/*TODO: Handle this. We have no render surface and not accelerated. */
}
/* Enable smooth shading */
glShadeModel( GL_SMOOTH );
/* Set the background black */
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
/* Depth buffer setup */
glClearDepth( 1.0f );
/* Enables Depth Testing */
glEnable( GL_DEPTH_TEST );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
/* The Type Of Depth Test To Do */
glDepthFunc( GL_LEQUAL );
/* Really Nice Perspective Calculations */
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
SDL_GL_SetSwapInterval(1);
}
示例6: lua_SDL_CreateWindowAndRenderer
static int lua_SDL_CreateWindowAndRenderer(State & state){
Stack * stack = state.stack;
SDL_Window * window = NULL;
SDL_Renderer * renderer = NULL;
int retval = SDL_CreateWindowAndRenderer(
stack->to<int>(1),
stack->to<int>(2),
(Uint32)stack->to<int>(3),
&window,
&renderer
);
Window * interfaceWindow = state.getInterface<Window>("LuaSDL_Window");
Renderer * interfaceRenderer = state.getInterface<Renderer>("LuaSDL_Renderer");
if (retval == 0){
if (window){
interfaceWindow->push(window);
}
else{
stack->pushNil();
}
if (renderer){
interfaceRenderer->push(renderer);
}
else{
stack->pushNil();
}
return 2;
}
else{
stack->push<bool>(false);
return 1;
}
}
示例7: setupSDL
// makes sure sdl sets up correctly
// if not then it prints out an error
void setupSDL()
{
if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_VIDEO) != 0)
{
printf("SDL failed to init: %s\n", SDL_GetError());
exit(1);
}
//Initialize SDL_mixer
/* if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
exit(1);
}*/
// Create window and renderer
// creates window for graphics
// if it fails to set up correctly an error is given
SDL_CreateWindowAndRenderer(600,400, SDL_WINDOW_SHOWN,&window, &renderer);
if ((window == NULL) || (renderer == NULL))
{
printf("SDL_CreateWindowAndRenderer Error: %s\n", SDL_GetError() );
exit(1);
}
}
示例8: main
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window;
SDL_Renderer *renderer;
SDL_CreateWindowAndRenderer(600, 450, 0, &window, &renderer);
int result = 0;
result |= testImage(renderer, SCREENSHOT_DIRNAME "/" SCREENSHOT_BASENAME); // absolute path
assert(result != 0);
chdir(SCREENSHOT_DIRNAME);
result = testImage(renderer, "./" SCREENSHOT_BASENAME); // relative path
assert(result != 0);
SDL_RenderPresent(renderer);
printf("you should see an image.\n");
SDL_Quit();
REPORT_RESULT();
return 0;
}
示例9: main
int main()
{
SDL_Window* win;
// initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
}
// initialize window and renderer
if(SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &win,
&ren) != 0) {
fprintf(stderr, "\nUnable to intialize window: %s\n", SDL_GetError());
}
init_physics();
// main lopp
for(;;) {
Uint32 t = SDL_GetTicks() + 1000/60;
// physics step
update_friction(0);
update_drive();
update_turn();
cpSpaceStep(space, 1.0/60.0);
debug_physics();
// events
SDL_Event e;
while(SDL_PollEvent(&e)) {
switch(e.type) {
case SDL_QUIT:
exit(0);
break;
}
}
const Uint8* k = SDL_GetKeyboardState(NULL);
controls.forward = k[SDL_SCANCODE_UP];
controls.back = k[SDL_SCANCODE_DOWN];
controls.left = k[SDL_SCANCODE_LEFT];
controls.right = k[SDL_SCANCODE_RIGHT];
// render
SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
SDL_RenderClear(ren);
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
render_objects();
SDL_RenderPresent(ren);
// time
if(SDL_GetTicks() < t) {
SDL_Delay(t - SDL_GetTicks());
}
}
return 0;
}
示例10: Window
SDLWindow::SDLWindow(uint32_t width, uint32_t height, uint8_t colorDepth, float pixelSize, float gamma, bool fullscreen)
: Window(width, height, colorDepth, pixelSize, gamma),
mFullscreen(fullscreen)
{
// Initialize SDL's subsystems - in this case, only video.
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
//throw std::runtime_error("Unable to init SDL: " + SDL_GetError());
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
throw 0;
}
// Attempt to create a window with pixels under specific mode.
SDL_CreateWindowAndRenderer(width, height, 0, &mWindow, &mRenderer);
// If we fail, return error.
if(mWindow == nullptr || mRenderer == nullptr)
{
//throw std::runtime_error()
fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
exit(1);
}
SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255);
SDL_RenderClear(mRenderer);
mDrawCanvas = SDL_CreateTexture(
mRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
width, height
);
mPixels.reset(new uint32_t[width * height]);
}
示例11: SDL_CreateWindowAndRenderer
void RSScreen::Init(int32_t zoomFactor){
this->scale =zoomFactor;
int32_t width = 320 * scale;
int32_t height = 200 * scale;
this->width = width;
this->height = height;
SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_HIDDEN, &sdlWindow, &sdlRenderer);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
printf("Unable to initialize SDL: %s\n",SDL_GetError());
return ;
}
sdlWindow = SDL_CreateWindow("RealSpace OBJ Viewer",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,this->width,this->height,SDL_WINDOW_OPENGL);
// Create an OpenGL context associated with the window.
SDL_GL_CreateContext(sdlWindow);
glViewport(0,0,this->width,this->height); // Reset The Current Viewport
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black Background
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
SDL_ShowWindow(sdlWindow);
}
示例12: main
int main(int argc, char **argv)
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_CreateWindowAndRenderer(SCREEN_WIDTH+232, SCREEN_HEIGHT+16, 0, &displayWindow, &displayRenderer);
SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
SDL_SetRenderDrawBlendMode(displayRenderer, SDL_BLENDMODE_BLEND);
SCREEN_SHIFT_X = 8;
SCREEN_SHIFT_Y = 8;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(null_loop_iter, 60, 1);
#endif
srand(time(NULL));
sound_init();
resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
load_resources();
last_time = clock();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop_iter, 60, 1);
#else
while (!done)
{
loop_iter();
}
#endif
sound_exit();
Quit(0);
return (0);
}
示例13: SDL_CreateWindowAndRenderer
Gfx::Gfx() {
SDL_CreateWindowAndRenderer(640, 480, 0, &this->_window, &this->_renderer);
SDL_SetWindowTitle(this->_window, "Cavestory");
std::cout << "Hello";
}
示例14: widthPx
ViewScreen::ViewScreen(unsigned int aWidth, unsigned int aHeight, unsigned int aBpp)
: widthPx(aWidth), heightPx(aHeight), bpp(aBpp), lastTick(SDL_GetTicks()) {
SDL_CreateWindowAndRenderer(widthPx, heightPx, SDL_WINDOW_SHOWN,
&window, &renderer);
if (window == NULL || renderer == NULL) {
throw Exception("Failed to initialize window or renderer");
}
}
示例15: graphics_init
graphics
graphics_init(int w, int h, const char* t) {
struct graphics_t *g = malloc(sizeof(struct graphics_t));
SDL_CreateWindowAndRenderer(w, h, 0, &g->window, &g->renderer);
SDL_SetWindowTitle(g->window, t);
g->sprite_sheets = map_init();
return g;
}