当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_CreateWindow函数代码示例

本文整理汇总了C++中SDL_CreateWindow函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_CreateWindow函数的具体用法?C++ SDL_CreateWindow怎么用?C++ SDL_CreateWindow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_CreateWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GLimp_SetMode


//.........这里部分代码省略.........
		if (perChannelColorBits == 4)
			perChannelColorBits = 0; /* Use minimum size for 16-bit color */

		/* Need alpha or else SGIs choose 36+ bit RGB mode */
		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);
#endif

		SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );

		/*SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );*/

		if(r_stereo->integer)
		{
			glConfig.stereoEnabled = qtrue;
			SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
		}
		else
		{
			glConfig.stereoEnabled = qfalse;
			SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
		}

		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

		// If not allowing software GL, demand accelerated
		if( !r_allowSoftwareGL->integer )
			SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

		if( ( screen = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
				glConfig.vidWidth, glConfig.vidHeight, flags ) ) == 0 )
		{
			Com_DPrintf( "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
			continue;
		}

		if( fullscreen )
		{
			SDL_DisplayMode mode;

			switch( testColorBits )
			{
				case 16: mode.format = SDL_PIXELFORMAT_RGB565; break;
				case 24: mode.format = SDL_PIXELFORMAT_RGB24;  break;
				default: Com_DPrintf( "testColorBits is %d, can't fullscreen\n", testColorBits ); continue;
			}

			mode.w = glConfig.vidWidth;
			mode.h = glConfig.vidHeight;
			mode.refresh_rate = glConfig.displayFrequency = Cvar_VariableIntegerValue( "r_displayRefresh" );
			mode.driverdata = NULL;

			if( SDL_SetWindowDisplayMode( screen, &mode ) < 0 )
			{
				Com_DPrintf( "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
				continue;
			}
		}

		SDL_SetWindowTitle( screen, CLIENT_WINDOW_TITLE );
		SDL_SetWindowIcon( screen, icon );
开发者ID:iMp-Rex,项目名称:OpenJK,代码行数:66,代码来源:sdl_glimp.cpp

示例2: SDL_SetVideoMode

SDL_Surface *
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
    SDL_DisplayMode desktop_mode;
    int display = GetVideoDisplay();
    int window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
    int window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
    int window_w;
    int window_h;
    Uint32 window_flags;
    Uint32 surface_flags;

    if (!SDL_GetVideoDevice()) {
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
            return NULL;
        }
    }

    SDL_GetDesktopDisplayMode(display, &desktop_mode);

    if (width == 0) {
        width = desktop_mode.w;
    }
    if (height == 0) {
        height = desktop_mode.h;
    }
    if (bpp == 0) {
        bpp = SDL_BITSPERPIXEL(desktop_mode.format);
    }

    /* See if we can simply resize the existing window and surface */
    if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
        return SDL_PublicSurface;
    }

    /* Destroy existing window */
    SDL_PublicSurface = NULL;
    if (SDL_ShadowSurface) {
        SDL_ShadowSurface->flags &= ~SDL_DONTFREE;
        SDL_FreeSurface(SDL_ShadowSurface);
        SDL_ShadowSurface = NULL;
    }
    if (SDL_VideoSurface) {
        SDL_VideoSurface->flags &= ~SDL_DONTFREE;
        SDL_FreeSurface(SDL_VideoSurface);
        SDL_VideoSurface = NULL;
    }
    if (SDL_VideoContext) {
        /* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */
        SDL_GL_DeleteContext(SDL_VideoContext);
        SDL_VideoContext = NULL;
    }
    if (SDL_VideoWindow) {
        SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
        SDL_DestroyWindow(SDL_VideoWindow);
    }

    /* Set up the event filter */
    if (!SDL_GetEventFilter(NULL, NULL)) {
        SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
    }

    /* Create a new window */
    window_flags = SDL_WINDOW_SHOWN;
    if (flags & SDL_FULLSCREEN) {
        window_flags |= SDL_WINDOW_FULLSCREEN;
    }
    if (flags & SDL_OPENGL) {
        window_flags |= SDL_WINDOW_OPENGL;
    }
    if (flags & SDL_RESIZABLE) {
        window_flags |= SDL_WINDOW_RESIZABLE;
    }
    if (flags & SDL_NOFRAME) {
        window_flags |= SDL_WINDOW_BORDERLESS;
    }
    GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
    SDL_VideoWindow =
        SDL_CreateWindow(wm_title, window_x, window_y, width, height,
                         window_flags);
    if (!SDL_VideoWindow) {
        return NULL;
    }
    SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon);

    SetupScreenSaver(flags);

    window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
    surface_flags = 0;
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
        surface_flags |= SDL_FULLSCREEN;
    }
    if ((window_flags & SDL_WINDOW_OPENGL) && (flags & SDL_OPENGL)) {
        surface_flags |= SDL_OPENGL;
    }
    if (window_flags & SDL_WINDOW_RESIZABLE) {
        surface_flags |= SDL_RESIZABLE;
    }
    if (window_flags & SDL_WINDOW_BORDERLESS) {
        surface_flags |= SDL_NOFRAME;
//.........这里部分代码省略.........
开发者ID:0xD34D,项目名称:supermariowar-android,代码行数:101,代码来源:SDL_compat.c

示例3: main

int main() {

    FILE *fp = fopen("a.yuv","rb");
    char * iter;
    int i,j;

    int width, height;

    if(!fp)
        perror("No File");

    width = 640;
    height = 480;

    printf(" Width %d Height %d \n",width,height);

    unsigned char *y = new unsigned char[width * height *1.5];
    int usize = width * height /4 ;

    unsigned  char *u = new unsigned char[usize];
    unsigned  char* v = new unsigned char[usize];

    unsigned char *u_iter = u;
    unsigned char *v_iter = v;


    int  k=fread(y,1,width*height *1.5,fp);
    printf(" %x %x %d\n",y[0],y[1],k);
    // for chroma
    for (int i=0; i < width *height /4; i+=2)
    {
        fread(u_iter++,1,1,fp);

        fread(v_iter++,1,1,fp);
        //printf(" %x %x\n",*u_iter,*v_iter);

    }


    // init SDL
    SDL_Surface *screen; // even with SDL2, we can still bring ancient code back
    SDL_Window *window;
    SDL_Surface *image;

    SDL_Renderer *renderer;
    SDL_Texture *texture;

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
        fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
        exit(1);
    }
    // create the window like normal
    window = SDL_CreateWindow("YUV Display", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0);

    // but instead of creating a renderer, we can draw directly to the screen
    //screen = SDL_GetWindowSurface(window);

    renderer = SDL_CreateRenderer(window, -1, 0);
    if (!renderer) {
        fprintf(stderr, "SDL: could not create renderer - exiting\n");
        exit(1);
    }

    // Allocate a place to put our YUV image on that screen
    texture = SDL_CreateTexture(
                  renderer,
                  SDL_PIXELFORMAT_IYUV,
                  SDL_TEXTUREACCESS_STREAMING,
                  width,
                  height
              );
    if (!texture) {
        fprintf(stderr, "SDL: could not create texture - exiting\n");
        exit(1);
    }
    // Cretae window and surface

    SDL_UpdateYUVTexture(
        texture,
        NULL,
        (unsigned char *)y,
        width,
        u,
        width/2,
        v,
        width/2
    );

    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, texture, NULL, NULL);
    SDL_RenderPresent(renderer);


    SDL_Delay(8000);
    SDL_DestroyWindow(window);
    SDL_Quit();
//


    return 0;
//.........这里部分代码省略.........
开发者ID:rusticmystic,项目名称:demo_sources,代码行数:101,代码来源:mnuyuv.c

示例4: window_init

void window_init(void) {
	// SDL base stuff
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
		error(1, SDL_GetError());
	}
	
	if ((windowMain = SDL_CreateWindow("Engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth, windowHeight, FLAGS)) == NULL) {
		error(1, SDL_GetError());
	}
	SDL_SetWindowMinimumSize(windowMain, 100, 100);
	
	// Renderer stuff
	windowMainGLContext = SDL_GL_CreateContext(windowMain); // yes, it's openGL stuff
	
	int oglId = -1;
	int rdnum = SDL_GetNumRenderDrivers();
	for (int i=0;i<rdnum;i++) {
		SDL_RendererInfo info;
		if (SDL_GetRenderDriverInfo(i, &info)) {
			continue;
		}
		if (!strcmp(info.name, "opengl")) {
			oglId = i;
		}
	}
	if (oglId == -1) {
		error(-1, "Cannot find the OpenGL renderer driver.");
	}
	
	if ((windowMainRenderer = SDL_CreateRenderer(windowMain, oglId, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)) < 0) {
		error(1, SDL_GetError());
	}
	
	// OpenGL stuff
	
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	if (SDL_GL_SetSwapInterval(17) < 0) {
		log_write(loggingLevel_warn, "Unable to setup VSync ! %s", SDL_GetError());
	}
	
	glShadeModel(GL_SMOOTH);
	
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
	glClearDepth(1.0f);
	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fov, (float)windowWidth/(float)windowHeight, 1.0f, 100.0f);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glViewport(0, 0, windowWidth, windowHeight);
	
	if (glGetError() != GL_NO_ERROR) {
		error(glGetError(), "OpenGL error.");
	}
	
	log_write(loggingLevel_debug, "GL version: %s", glGetString(GL_VERSION));
	log_write(loggingLevel_debug, "GL vendor: %s", glGetString(GL_VENDOR));
	log_write(loggingLevel_debug, "GL renderer: %s", glGetString(GL_RENDERER));
	log_write(loggingLevel_debug, "Video driver: %s", SDL_GetCurrentVideoDriver());
	
	// nothing else to do
}
开发者ID:Firew0lf,项目名称:Engine,代码行数:74,代码来源:window.c

示例5: init

/*
--------------------------------------------------------------------------------
                                      INIT
--------------------------------------------------------------------------------
 *  Master init function.  Being a game made in SDL2, SDL2 and its subsystems
 *  are obviously critical to the functionality of the program.  Also, their
 *  initialization is kept here because it's tidier.
*/
bool init( void )
{
    /*  Init SDL */
    if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
    {
        printf("ERROR:  Could not init SDL.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }

    /*  Init SDL_image */
    if( ( IMG_Init( IMG_INIT_PNG ) & IMG_INIT_PNG ) == false )
    {
        printf("ERROR:  Could not init SDL_image.  IMG Error:  %s\n",
                IMG_GetError() );
        return( false );
    }

    /*  Init SDL_mixer */
    if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
    {
        printf("ERROR:  Could not init SDL_mixer.  Mix Error:  %s\n",
                Mix_GetError() );
        return( false );
    }


    /*  Init SDL_ttf */
    if( TTF_Init() == -1 )
    {
        printf("ERROR:  Could not init SDL_ttf.  TTF Error:  %s\n",
                TTF_GetError() );
        return( false );
    }


    /*  Create our window */
    gWindow = SDL_CreateWindow( "BELTED (working title)",
            SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
            WWIDTH, WHEIGHT, SDL_WINDOW_SHOWN );
    if( gWindow == NULL )
    {
        printf("ERROR:  Could not create window.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }

    /*
     *  Create the renderer
     *
     *  We check for the limiting of FPS as a futureproofing thing.  Also,
     *  theoretically a bug-solving or performance thing.
     */

    /*  If they want to limit FPS, don't vsync */
    if( limitFPS )
        gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );

    /*  Otherwise, use vsync */
    else
    {
        gRenderer = SDL_CreateRenderer( gWindow, -1,
                SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    }
    if( gRenderer == NULL )
    {
        printf("ERROR:  Could not create renderer.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }


    /*  Just for shits and giggles, we'll seed random here */
    srand( (unsigned int)time(NULL) );

    /*  Init boundary dimensions */
    BWIDTH = WWIDTH;
    BHEIGHT = WHEIGHT - 100;

    /*  Init colors */
    init_colors();

    /*  Init blend mode */
    SDL_SetRenderDrawBlendMode( gRenderer, SDL_BLENDMODE_BLEND );

    /*  Init transitions */
    init_transition();


    /*  If we made it this far, we're golden */
    return( true );
}
开发者ID:jahendrie,项目名称:belted,代码行数:100,代码来源:init.cpp

示例6: sdl_init

static int sdl_init(void **ctx, platform_params *params, void (*onFrame)(void *), void *user, int audio_only)
{
    *ctx = 0;
#ifdef __MINGW32__
    putenv("SDL_AUDIODRIVER=winmm");
#endif
    int flags = audio_only ? SDL_INIT_AUDIO : SDL_INIT_EVERYTHING & ~(SDL_INIT_TIMER | SDL_INIT_HAPTIC);
    if (SDL_Init(flags) < 0)
    {
        printf("error: sdl2 init failed: %s\n", SDL_GetError());
        return 0;
    }
#if PLATFORM_SDL
    platform_ctx *platform = (platform_ctx *)calloc(1, sizeof(platform_ctx));
    platform->onFrame = onFrame;
    platform->user   = user;
    platform->params = params;
    /*SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);*/
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
    //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);

    //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#ifndef EMSCRIPTEN
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);
    platform->window = SDL_CreateWindow("LVG Player", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 800,
        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
    if (!platform->window)
    {
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
        platform->window = SDL_CreateWindow("LVG Player", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 800,
            SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
        if (!platform->window)
        {
            printf("error: sdl2 init failed: %s\n", SDL_GetError()); fflush(stdout);
            sdl_release(platform);
            return 0;
        }
    }
    platform->context = SDL_GL_CreateContext(platform->window);
    SDL_GL_MakeCurrent(platform->window, platform->context);
#ifndef EMSCRIPTEN
    if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
    {
        printf("error: glad init failed\n");
        sdl_release(platform);
        return 0;
    }
#endif
    *ctx = platform;
#endif
    return 1;
}
开发者ID:lieff,项目名称:lvg,代码行数:63,代码来源:platform_sdl.c

示例7: sdl_init

void sdl_init(int width, int height, bool fullscreen) {
  sdlCurrentFrame = sdlNextFrame = 0;
  int drv_index = -1, it = 0;
  char rendername[256] = { 0 };
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
    fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
    exit(1);
  }

  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
  SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

  fullscreen_flags = fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0;
  window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | fullscreen_flags);
  if(!window) {
    fprintf(stderr, "SDL: could not create window - exiting\n");
    exit(1);
  }

  SDL_GLContext ctx = SDL_GL_CreateContext(window);
  SDL_GL_MakeCurrent(window, ctx);

  glGetStringAPI = (glGetString_Func)SDL_GL_GetProcAddress("glGetString");

  for(it = 0; it < SDL_GetNumRenderDrivers(); it++) {
      SDL_RendererInfo info;
      SDL_GetRenderDriverInfo(it,&info);

      strcat(rendername, info.name);
      strcat(rendername, " ");

      if(strcmp("opengles2", info.name) == 0)
          drv_index = it;
  }
  fprintf(stdout, "Available Renderers: %s\n", rendername);
  fprintf(stdout, "Vendor     : %s\n", glGetStringAPI(GL_VENDOR));
  fprintf(stdout, "Renderer   : %s\n", glGetStringAPI(GL_RENDERER));
  fprintf(stdout, "Version    : %s\n", glGetStringAPI(GL_VERSION));
  fprintf(stdout, "Extensions : %s\n", glGetStringAPI(GL_EXTENSIONS));

  SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");

  SDL_SetRelativeMouseMode(SDL_TRUE);
  renderer = SDL_CreateRenderer(window, drv_index, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  if (!renderer) {
    printf("SDL_CreateRenderer failed: %s\n", SDL_GetError());
    exit(1);
  }

  SDL_ShowCursor(SDL_DISABLE);

  bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, width, height);
  if (!bmp) {
    fprintf(stderr, "SDL: could not create texture - exiting\n");
    exit(1);
  }

  mutex = SDL_CreateMutex();
  if (!mutex) {
    fprintf(stderr, "Couldn't create mutex\n");
    exit(1);
  }
}
开发者ID:AreaScout,项目名称:moonlight-embedded,代码行数:65,代码来源:sdl.c

示例8: main

int main(int argc, char *argv[]) {
    int w = 5, h = 5;
    SDL_Window *window;
    SDL_Renderer *renderer;
    SDL_Surface *background;
    SDL_Rect bg_rect = { 0, 0, 12, 12 };
    SDL_Surface *surface;
    SDL_Rect tgt_rect = { 0, 0, 5, 5 };
    Uint32 pf;
    SDL_Surface *new_surface;
    SDL_Rect tgt_rect2 = { 6, 0, 5, 5 };
    SDL_Texture *bg_tex;
    Uint32 first_pixel;
    Uint8 r,g,b,a;
    Uint32 colour_key;
    int waiting;

    SDL_Init(SDL_INIT_VIDEO);

    window = SDL_CreateWindow("Color key conversion test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 100, 100, 0);
    renderer = SDL_CreateRenderer(window, -1, 0);
    SDL_RenderSetScale(renderer, 8, 8);

    // create green background surface
    background = SDL_CreateRGBSurface(0, 12, 12, 32, 0,0,0,0);
    SDL_FillRect(background, &bg_rect, SDL_MapRGB(background->format, 100,200,100));

    // create 16-bit surface
    surface = SDL_CreateRGBSurfaceFrom(pixel_data, w, h, 16, w*2, 0x0000f800,0x000007e0,0x0000001f,0);
    SDL_SetColorKey(surface, SDL_TRUE, 0xB54A);

    // blit original surface to left hand side of background
    SDL_BlitSurface(surface, NULL, background, &tgt_rect);

    // convert surface to 32-bit (suitable for window)
    pf = SDL_GetWindowPixelFormat(window);
    new_surface = SDL_ConvertSurfaceFormat(surface, pf, 0);

    // blit converted surface to right hand side
    SDL_BlitSurface(new_surface, NULL, background, &tgt_rect2);

    // show everything
    bg_tex = SDL_CreateTextureFromSurface(renderer, background);
    SDL_RenderCopy(renderer, bg_tex, NULL, &bg_rect);
    SDL_RenderPresent(renderer);

    // print value of first pixel
    first_pixel = ((Uint32 *) new_surface->pixels)[0];
    SDL_GetRGBA(first_pixel, new_surface->format, &r,&g,&b,&a);
    printf("First pixel = %08x (%d,%d,%d alpha %d)\n", first_pixel, r,g,b,a);
    // print value of colour key
    SDL_GetColorKey(new_surface, &colour_key);
    SDL_GetRGB(colour_key, new_surface->format, &r,&g,&b);
    printf("colour key  = %08x (%d,%d,%d)\n", colour_key, r,g,b);

    waiting = 1;
    while (waiting) {
        SDL_Event evt;
        SDL_WaitEvent(&evt);
        if (evt.type == SDL_QUIT)
            waiting = 0;
    }

    SDL_FreeSurface(new_surface);
    SDL_FreeSurface(surface);
    SDL_DestroyTexture(bg_tex);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}
开发者ID:ejrh,项目名称:hex,代码行数:72,代码来源:colour_key_conversion_test.c

示例9: SDL_CreateWindow

bool openvox::Window::init(GameDisplayMode* displayMode /*= nullptr*/) {
    if (isInitialized()) return false;
    if (displayMode) m_displayMode = *displayMode;

    SDL_WindowFlags flags = (SDL_WindowFlags)DEFAULT_WINDOW_FLAGS;
    if (m_displayMode.isResizable) flags = (SDL_WindowFlags)(flags | SDL_WINDOW_RESIZABLE);
    if (m_displayMode.isBorderless) flags = (SDL_WindowFlags)(flags | SDL_WINDOW_BORDERLESS);
    if (m_displayMode.isFullscreen) flags = (SDL_WindowFlags)(flags | SDL_WINDOW_FULLSCREEN);
    m_window = SDL_CreateWindow(DEFAULT_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_displayMode.screenWidth, m_displayMode.screenHeight, flags);

    // Create The Window
    if (m_window == nullptr) {
        printf("Window Creation Failed\r\n");
        return false;
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, (int)m_displayMode.major);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, (int)m_displayMode.minor);
    if (m_displayMode.core) {
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    } else {
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
    }
    m_glc = SDL_GL_CreateContext((SDL_Window*)m_window);
    SDL_GL_MakeCurrent((SDL_Window*)m_window, (SDL_GLContext)m_glc);

    // Check for a valid context
    if (m_glc == nullptr) {
        printf("Could Not Create OpenGL Context");
        return false;
    }

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        printf("Glew failed to initialize. Your graphics card is probably WAY too old. Or you forgot to extract the .zip. It might be time for an upgrade :)");
        return false;
    }

    // Create default clear values
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);

    // Initialize Frame Buffer
    glViewport(0, 0, getWidth(), getHeight());

    { // Get supported window resolutions
        SDL_DisplayMode mode;
        // TODO(Ben): Handle other displays indices.
        int displayIndex = 0;
        int numDisplayModes = SDL_GetNumDisplayModes(displayIndex);
        for (int i = 0; i < numDisplayModes; i++) {
            SDL_GetDisplayMode(displayIndex, i, &mode);
            u32v2 res(mode.w, mode.h);
            if (i == 0 || m_supportedResolutions.back() != res) {
                m_supportedResolutions.push_back(res);
            }
        }
    }

    // Set More Display Settings
    setSwapInterval(m_displayMode.swapInterval, true);

    // Push input from this window and receive quit signals
    // TODO(Ben): Input
    // openvox::InputDispatcher::init(this);
    // openvox::InputDispatcher::window.onClose += makeDelegate(*this, &Window::onQuitSignal);
    // openvox::InputDispatcher::onQuit += makeDelegate(*this, &Window::onQuitSignal);
    // openvox::InputDispatcher::window.onResize += makeDelegate(*this, &Window::onResize);
    m_quitSignal = false;

    return true;
}
开发者ID:VoxelGameDev,项目名称:OpenVox,代码行数:73,代码来源:Window.cpp

示例10: SDL_GetError

std::string SceneRenderer::renderImage2(FBEntity const& file, std::vector<ModelFaceBase*> *) {
    int width = Settings::Instance()->SDL_Window_Width;
    int height = Settings::Instance()->SDL_Window_Height;

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
        Settings::Instance()->funcDoLog(Settings::Instance()->string_format("[SceneRenderer] Render Error: SDL could not initialize! SDL Error: %s\n", SDL_GetError()));
    else {
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

        SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");

        SDL_DisplayMode current;
        SDL_GetCurrentDisplayMode(0, &current);

        SDL_Window *gWindow = SDL_CreateWindow("Kuplung", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, Settings::Instance()->SDL_Window_Flags);
        SDL_GLContext glContext;
        if (gWindow == NULL)
            Settings::Instance()->funcDoLog(Settings::Instance()->string_format("[SceneRenderer] Render Error: Window could not be created! SDL Error: %s\n", SDL_GetError()));
        else {
            glContext = SDL_GL_CreateContext(gWindow);
            if (!glContext)
                Settings::Instance()->funcDoLog(Settings::Instance()->string_format("[SceneRenderer] Render Error: Unable to create OpenGL context! SDL Error: %s\n", SDL_GetError()));
            else {
                if (SDL_GL_MakeCurrent(gWindow, glContext) < 0)
                    Settings::Instance()->funcDoLog(Settings::Instance()->string_format("[SceneRenderer] Render Warning: Unable to set current context! SDL Error: %s\n", SDL_GetError()));
                else {
                    glViewport(0, 0, width, height);
                    glClearColor(Settings::Instance()->guiClearColor.r, Settings::Instance()->guiClearColor.g, Settings::Instance()->guiClearColor.b, Settings::Instance()->guiClearColor.w);
                    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

                    this->managerObjects.render();
                    //managerObjects->renderSkybox();

//                    // render models
//                    for (int i=0; i<(int)(*meshModelFaces).size(); i++) {
//                        ModelFaceBase* mmf = (*meshModelFaces)[i];

//                        glm::mat4 mtxModel = glm::mat4(1.0);

//                        // reposition like the grid perspective
//                        if (managerObjects->Setting_FixedGridWorld)
//                            mtxModel *= managerObjects->grid->matrixModel;

//                        // scale
//                        mtxModel = glm::scale(mtxModel, glm::vec3(mmf->scaleX->point, mmf->scaleY->point, mmf->scaleZ->point));

//                        // rotate
//                        mtxModel = glm::translate(mtxModel, glm::vec3(0, 0, 0));
//                        mtxModel = glm::rotate(mtxModel, glm::radians(mmf->rotateX->point), glm::vec3(1, 0, 0));
//                        mtxModel = glm::rotate(mtxModel, glm::radians(mmf->rotateY->point), glm::vec3(0, 1, 0));
//                        mtxModel = glm::rotate(mtxModel, glm::radians(mmf->rotateZ->point), glm::vec3(0, 0, 1));
//                        mtxModel = glm::translate(mtxModel, glm::vec3(0, 0, 0));

//                        // translate
//                        mtxModel = glm::translate(mtxModel, glm::vec3(mmf->positionX->point, mmf->positionY->point, mmf->positionZ->point));

//                        // general
//                        mmf->setOptionsFOV(managerObjects->Setting_FOV);

//                        // outlining
//                        mmf->setOptionsSelected(0);
//                        mmf->setOptionsOutlineColor(managerObjects->Setting_OutlineColor);
//                        mmf->setOptionsOutlineThickness(managerObjects->Setting_OutlineThickness);

//                        // lights
//                        mmf->lightSources = managerObjects->lightSources;

//                        mmf->matrixProjection = managerObjects->matrixProjection;
//                        mmf->matrixCamera = managerObjects->camera->matrixCamera;
//                        mmf->vecCameraPosition = managerObjects->camera->cameraPosition;
//                        mmf->matrixModel = mtxModel;
//                        mmf->renderModel();
//                    }

                    SDL_GL_SwapWindow(gWindow);

                    SDL_Surface *image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0);

                    glReadBuffer(GL_FRONT);
                    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);

                    // flip vertically
                    int index;
                    void* temp_row;
                    int height_div_2;
                    temp_row = (void *)malloc(image->pitch);
                    if(NULL == temp_row)
                        Settings::Instance()->funcDoLog("Not enough memory for image inversion");
                    height_div_2 = int(image->h * .5);
                    for (index = 0; index < height_div_2; index++) {
                        memcpy((Uint8 *)temp_row,(Uint8 *)(image->pixels) + image->pitch * index, image->pitch);
//.........这里部分代码省略.........
开发者ID:supudo,项目名称:Kuplung,代码行数:101,代码来源:SceneRenderer.cpp

示例11: main

int main(int argc, char *argv[])
{
	SDL_Init(SDL_INIT_VIDEO);
  
	SDL_Window *window = SDL_CreateWindow("CopyCraft", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
	
	SDL_GLContext glcontext = SDL_GL_CreateContext(window);

	init_opengl();

	glewInit();

	init();

	float x = 0.0, y = 30.0;

	SDL_Event event; 
	bool done = 0;

	printf("total faces drawn: %d\n", get_total_faces());

	int i,j,k;
	float rot_amount;

	//Initialise VBO - do only once, at start of program
	//Create a variable to hold the VBO identifier
	GLuint triangleVBO[2];

	float *verticies;
	float *colors;
	float *texcoords;
	verticies = new float[get_total_faces()*4*3];
	colors = new float[get_total_faces()*4*3];
	texcoords = new float[get_total_faces()*4*2];

	int num_faces_populated;
	num_faces_populated = populate_verticies(verticies, colors, texcoords);

	printf("Number of faces populated: %d\n", num_faces_populated);

	//Create a new VBO and use the variable id to store the VBO id
	glGenBuffers(3, &triangleVBO[0]);

	//Make the new VBO active
	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[0]);
	//Upload vertex data to the video device
	glBufferData(GL_ARRAY_BUFFER, sizeof(float)*num_faces_populated*4*3, verticies, GL_STATIC_DRAW);

	//Make the new VBO active
	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[1]);
	//Upload vertex data to the video device
	glBufferData(GL_ARRAY_BUFFER, sizeof(float)*num_faces_populated*4*3, colors, GL_STATIC_DRAW);

	//Make the new VBO active
	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[2]);
	//Upload vertex data to the video device
	glBufferData(GL_ARRAY_BUFFER, sizeof(float)*num_faces_populated*4*2, texcoords, GL_STATIC_DRAW);

	//Make the new VBO active. Repeat here incase changed since initialisation
	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[0]);
	glVertexPointer(3, GL_FLOAT, 0, NULL);

	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[1]);
	glColorPointer(3, GL_FLOAT, 0, 0);

	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO[2]);
	glTexCoordPointer(2, GL_FLOAT, 0, 0);
 
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY); 
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	while(!done)
	{
		while(SDL_PollEvent(&event))

		{
			if(event.type == SDL_QUIT || event.type == SDL_QUIT)
				done = 1;
		}
		
		glLoadIdentity();

		glClearColor(0,0,0,1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		gluLookAt(16.0f,40.0f, 20.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

		rot_amount = SDL_GetTicks()/10;

		glPushMatrix();
			glRotatef(rot_amount,0,1,0);
			//Actually draw the triangle, giving the number of vertices provided
			glDrawArrays(GL_QUADS, 0, num_faces_populated*4);
		glPopMatrix();

		SDL_GL_SwapWindow(window);
	} 

	SDL_GL_DeleteContext(glcontext);  
//.........这里部分代码省略.........
开发者ID:Tenderfoot,项目名称:CopyCraft,代码行数:101,代码来源:main.cpp

示例12: SDL_CreateWindow

void Renderer::init()
{
    // TODO: android/ios
    // _width = deviceWidth;
    // _height = deviceHeight;
    // Game::getInstance()->engineSettings()->setFullscreen(true);
    // Game::getInstance()->engineSettings()->setScale(1); //or 2, if fullhd device

    std::string message =  "SDL_CreateWindow " + std::to_string(_size.width()) + "x" + std::to_string(_size.height()) + "x" +std::to_string(32)+ " - ";

    uint32_t flags = SDL_WINDOW_SHOWN;
    if (Game::getInstance()->settings()->fullscreen())
    {
        flags |= SDL_WINDOW_FULLSCREEN;
    }

    _sdlWindow = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _size.width(), _size.height(), flags);
    if (!_sdlWindow)
    {
        throw Exception(message + "[FAIL]");
    }

    Logger::info("RENDERER") << message + "[OK]" << std::endl;

    message =  "SDL_CreateRenderer - ";
    _sdlRenderer = SDL_CreateRenderer(_sdlWindow, -1, SDL_RENDERER_ACCELERATED);
    if (!_sdlRenderer)
    {
        throw Exception(message + "[FAIL]");
    }

    Logger::info("RENDERER") << message + "[OK]" << std::endl;

    SDL_SetRenderDrawBlendMode(_sdlRenderer, SDL_BLENDMODE_BLEND);

    if (Game::getInstance()->settings()->scale() != 0)
    {
        switch (Game::getInstance()->settings()->scale())
        {
            default:
            case 1:
                _size.setWidth((int)(_size.width() / (_size.height() / 480.0)));
                _size.setHeight(480);
                break;
            case 2:
                _size.setWidth((int)(_size.width() / (_size.height() / 960.0)));
                _size.setHeight(960);
                break;
        }
        SDL_RenderSetLogicalSize(_sdlRenderer, _size.width(), _size.height());
        SDL_RenderGetScale(_sdlRenderer, &_scaleX, &_scaleY);
    }

    SDL_RendererInfo rendererInfo;
    SDL_GetRendererInfo(_sdlRenderer, &rendererInfo);

    Logger::info("RENDERER") << "name: " << rendererInfo.name << std::endl;
    if (rendererInfo.flags & SDL_RENDERER_SOFTWARE)
    {
        Logger::info("RENDERER") << "flags: SDL_RENDERER_SOFTWARE" << std::endl;
    }
    if (rendererInfo.flags & SDL_RENDERER_ACCELERATED)
    {
        Logger::info("RENDERER") << "flags: SDL_RENDERER_ACCELERATED" << std::endl;
    }
    Logger::info("RENDERER") << "num_texture_formats: " << rendererInfo.num_texture_formats << std::endl;
    for (unsigned int i = 0; i != 16; i++)
    {
        auto& info = Logger::info("RENDERER");
        info << "texture_formats[" << i << "]: ";
        auto format = rendererInfo.texture_formats[i];

        switch (format)
        {
            case SDL_PIXELFORMAT_INDEX1LSB:
                info << "SDL_PIXELFORMAT_INDEX1LSB";
                break;
            case SDL_PIXELFORMAT_INDEX1MSB:
                info << "SDL_PIXELFORMAT_INDEX1MSB";
                break;
            case SDL_PIXELFORMAT_INDEX4LSB:
                info << "SDL_PIXELFORMAT_INDEX4LSB";
                break;
            case SDL_PIXELFORMAT_INDEX4MSB:
                info << "SDL_PIXELFORMAT_INDEX4MSB";
                break;
            case SDL_PIXELFORMAT_INDEX8:
                info << "SDL_PIXELFORMAT_INDEX8";
                break;
            case SDL_PIXELFORMAT_RGBA8888:
                info << "SDL_PIXELFORMAT_RGBA8888";
                break;
            case SDL_PIXELFORMAT_ARGB8888:
                info << "SDL_PIXELFORMAT_ARGB8888";
                break;
            case SDL_PIXELFORMAT_RGB888:
                info << "SDL_PIXELFORMAT_RGB888";
                break;
            default:
                info << format;
//.........这里部分代码省略.........
开发者ID:nishazzar,项目名称:falltergeist,代码行数:101,代码来源:Renderer.cpp

示例13: main

int
main(int argc, char *argv[])
{

    int index;                  /* index of last key we pushed in the bitmap font */
    SDL_Window *window;
    SDL_Event event;            /* last event received */
    SDLMod mod;                 /* key modifiers of last key we pushed */
    SDL_ScanCode scancode;      /* scancode of last key we pushed */

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("Error initializing SDL: %s", SDL_GetError());
    }
    /* create window */
    window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
    /* create renderer */
    renderer = SDL_CreateRenderer(window, -1, 0);

    /* load up our font */
    loadFont();

    /* draw the background, we'll just paint over it */
    SDL_SetRenderDrawColor(renderer, bg_color.r, bg_color.g, bg_color.b,
                           bg_color.unused);
    SDL_RenderFillRect(renderer, NULL);
    SDL_RenderPresent(renderer);

    int done = 0;
    /* loop till we get SDL_Quit */
    while (SDL_WaitEvent(&event)) {
        switch (event.type) {
        case SDL_QUIT:
            done = 1;
            break;
        case SDL_KEYDOWN:
            index = keyToIndex(event.key.keysym);
            scancode = event.key.keysym.scancode;
            mod = event.key.keysym.mod;
            if (scancode == SDL_SCANCODE_DELETE) {
                /* if user hit delete, delete the last character */
                backspace();
                lastCharWasColon = 0;
            } else if (lastCharWasColon && scancode == SDL_SCANCODE_0
                       && (mod & KMOD_SHIFT)) {
                /* if our last key was a colon and this one is a close paren, the make a hoppy face */
                backspace();
                drawIndex(32);  /* index for happy face */
                numChars++;
                drawCursor();
                lastCharWasColon = 0;
            } else if (index != -1) {
                /* if we aren't doing a happy face, then just draw the normal character */
                drawIndex(index);
                numChars++;
                drawCursor();
                lastCharWasColon =
                    (event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON
                     && (event.key.keysym.mod & KMOD_SHIFT));
            }
            /* check if the key was a colon */
            /* draw our updates to the screen */
            SDL_RenderPresent(renderer);
            break;
#ifdef __IPHONEOS__
        case SDL_MOUSEBUTTONUP:
            /*      mouse up toggles onscreen keyboard visibility
               this function is available ONLY on iPhone OS
             */
            SDL_iPhoneKeyboardToggle(window);
            break;
#endif
        }
    }
    cleanup();
    return 0;
}
开发者ID:Akitory4,项目名称:gplayer,代码行数:76,代码来源:keyboard.c

示例14: main

int main(int argc, char **argv)
{
    bool fullscreen = false;

    if (SDL_Init(0) != 0){
        ERR("SDL_Init\n");
        return 1;
    }

    SDL_Window* Window = SDL_CreateWindow("SDL Nine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
    if (!Window) {
        ERR("SDL_CreateWindow\n");
        return 1;
    }

    d3d = SDL_Direct3DCreate9Ex(Window);
    if (!d3d) {
        ERR("X11_Direct3DCreate9\n");
        return 1;
    }

    {
        HWND FakeWnd= (HWND)Window;

        D3DDISPLAYMODEEX mode;
        D3DPRESENT_PARAMETERS d3dpp;
        fillin_present_parameters(Window, SCREEN_WIDTH, SCREEN_HEIGHT, fullscreen, d3dpp, mode);

        // create a device class using this information and the info from the d3dpp stuct
        HRESULT hr = d3d->CreateDeviceEx(D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            FakeWnd,
            D3DCREATE_HARDWARE_VERTEXPROCESSING,
            &d3dpp, &mode, 
            &d3ddev);

        if (FAILED(hr)) {
            ERR("X11_Direct3DCreate9\n");
            return 1;
        }
    }

    init_graphics();    // call the function to initialize the triangle

    Uint32 MainWindowID = SDL_GetWindowID(Window);
    bool quit = false;
    SDL_Event e;

    //While application is running
    while (!quit)
    {
        //Handle events on queue
        while (SDL_PollEvent(&e) != 0)
        {
            //User requests quit
            if (e.type == SDL_QUIT)
            {
                quit = true;
            }
            else if (e.type == SDL_WINDOWEVENT && e.window.windowID == MainWindowID)
            {
                switch (e.window.event) {
                case SDL_WINDOWEVENT_SIZE_CHANGED:
                    {
                        int width = e.window.data1;
                        int height = e.window.data2;

                        bool ok = set_window_size(Window, width, height, fullscreen);
                        if (ok)
                            load_triangle(width, height, v_buffer);
                    } break;
                }
            }
            else if (e.type == SDL_KEYDOWN && e.window.windowID == MainWindowID && e.key.keysym.sym == SDLK_F11 && e.key.state == SDL_PRESSED)
            {
                fullscreen = !fullscreen;
                bool ok = set_window_size(Window, SCREEN_WIDTH, SCREEN_HEIGHT, fullscreen);
                if (ok)
                    load_triangle(SCREEN_WIDTH, SCREEN_HEIGHT, v_buffer);
            }
        }

        //Render quad
        render_frame();
    }

    // clean up DirectX
    {
        v_buffer->Release();    // close and release the vertex buffer
        d3ddev->Release();    // close and release the 3D device
        d3d->Release();    // close and release Direct3D
    }

    SDL_Quit();

    return 0;
}
开发者ID:EoD,项目名称:Xnine,代码行数:97,代码来源:triangle_SDL.cpp

示例15: draw13_window_create

static int draw13_window_create(sdl_window_info *window, int width, int height)
{
	// allocate memory for our structures
	sdl_info *sdl = (sdl_info *) osd_malloc(sizeof(*sdl));

	mame_printf_verbose("Enter draw13_window_create\n");

	memset(sdl, 0, sizeof(*sdl));

	window->dxdata = sdl;

	sdl->extra_flags = (window->fullscreen ?
			SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);

	// create the SDL window
	window->sdl_window = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED_DISPLAY(window->monitor->handle), SDL_WINDOWPOS_UNDEFINED,
			width, height, sdl->extra_flags);

	if (window->fullscreen && video_config.switchres)
	{
		SDL_DisplayMode mode;
		SDL_GetCurrentDisplayMode(window->monitor->handle, &mode);
		mode.w = width;
		mode.h = height;
		if (window->refresh)
			mode.refresh_rate = window->refresh;
		if (window->depth)
		{
			switch (window->depth)
			{
			case 15:
				mode.format = SDL_PIXELFORMAT_RGB555;
				break;
			case 16:
				mode.format = SDL_PIXELFORMAT_RGB565;
				break;
			case 24:
				mode.format = SDL_PIXELFORMAT_RGB24;
				break;
			case 32:
				mode.format = SDL_PIXELFORMAT_RGB888;
				break;
			default:
				mame_printf_warning("Ignoring depth %d\n", window->depth);
			}
		}
		SDL_SetWindowDisplayMode(window->sdl_window, &mode);	// Try to set mode
	}
	else
		SDL_SetWindowDisplayMode(window->sdl_window, NULL);	// Use desktop

	// create renderer

	if (video_config.waitvsync)
		sdl->sdl_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
	else
		sdl->sdl_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_ACCELERATED);

	if (!sdl->sdl_renderer)
	{
		fatalerror("Error on creating renderer: %s \n", SDL_GetError());
	}

    //SDL_SelectRenderer(window->sdl_window);

	SDL_ShowWindow(window->sdl_window);
	//SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
	SDL_RaiseWindow(window->sdl_window);
	SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);


	sdl->blittimer = 3;

	// in case any textures try to come up before these are validated,
	// OpenGL guarantees all implementations can handle something this size.
	sdl->texture_max_width = 64;
	sdl->texture_max_height = 64;

	SDL_RenderPresent(sdl->sdl_renderer);
	mame_printf_verbose("Leave draw13_window_create\n");
	return 0;
}
开发者ID:kleopatra999,项目名称:mess-svn,代码行数:82,代码来源:draw13.c


注:本文中的SDL_CreateWindow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。