Example #1
0
	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);
	}
Example #2
0
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;
}
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!!");
}
Example #4
0
TinyGameLibrary::TinyGameLibrary(int width, int height, int scale)
{
    m_renderWidth = width;
    m_renderHeight = height;

    width *= scale;
    height *= scale;

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        cerr << "Unable to initialize SDL: " << SDL_GetError() << endl;
        exit(1);
    }

    if (SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_OPENGL, &m_window, &m_renderer)) {
        cerr << "Unable to create SDL window or renderer: " << SDL_GetError() << endl;
        exit(1);
    }

    if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024)) {
        cerr << "Unable to initialize SDL audio: " << SDL_GetError() << endl;
        exit(1);
    }

    SDL_SetRenderDrawColor(m_renderer, 0, 0, 0, 255);
    SDL_RenderSetScale(m_renderer, (float)scale, (float)scale);

    m_spriteSheet = nullptr;
    m_player = nullptr;
}
Example #5
0
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;
}
Example #6
0
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);
}
Example #7
0
	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;
		}
	}
// 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);
    }
    
  }
Example #9
0
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;
}
Example #10
0
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;
}
Example #11
0
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]);
}
Example #12
0
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);
}
Example #13
0
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);
}
Example #14
0
Gfx::Gfx() {

	SDL_CreateWindowAndRenderer(640, 480, 0, &this->_window, &this->_renderer);
	SDL_SetWindowTitle(this->_window, "Cavestory");
	
	std::cout << "Hello";
}
Example #15
0
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");
	}
}
Example #16
0
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;
}
Example #17
0
void initRenderer(){
 	SDL_Init(SDL_INIT_VIDEO);
    SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_OPENGL, &displayWindow, &displayRenderer);
    SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
    if ((displayRendererInfo.flags & SDL_RENDERER_ACCELERATED) == 0 || (displayRendererInfo.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
        printf( " WARNING : NO ACCELEARION !!! \n" ); 
    }
}
Example #18
0
int init(int width, int height) {

	//Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0) {

		printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
		
		return 1;
	} 
	
	//Create window	
	SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN, &window, &renderer);

	//set up screen pixel buffer
	create_renderer(&pb, SCREEN_WIDTH, SCREEN_HEIGHT);
	
	//set up vector ball pixel buffer
	create_renderer(&vb, VECTOR_BALL_WIDTH, VECTOR_BALL_HEIGHT);
	
	//set up screen texture
	screen = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, pb.width, pb.height);
	
	//set up vector_ball texture
	vector_ball = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, vb.width, vb.height);
	
	if (window == NULL) { 
		
		printf ("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		
		return 1;
	}

	//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	//SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);

	if (screen == NULL) { 
		
		printf ("Texture could not be created! SDL_Error: %s\n", SDL_GetError());
		
		return 1;
	}
	
	if (pb.pixels == NULL) {
	
		printf ("Error allocating pixel buffer");
		
		return 1;
	}
	
	if (vb.pixels == NULL) {
	
		printf ("Error allocating pixel buffer");
		
		return 1;
	}

	return 0;
}
Example #19
0
/**
 * subsystems constructor
 */
Video_subsystem::Video_subsystem(int width , int height , bool fullscreen)
{
    int alright;
    if(fullscreen)
        alright = SDL_CreateWindowAndRenderer(width , height , SDL_WINDOW_FULLSCREEN_DESKTOP , &main_window_ , &main_renderer_);
    else
        alright = SDL_CreateWindowAndRenderer(width , height , 0 , &main_window_ , &main_renderer_);
    if(alright == -1)
    {
        printf("Couldn't initialize video subsystem. \n");
        printf("Error = %s\n",SDL_GetError());
        is_created_=false;
    }
    else
    {
        is_created_=true;
    }
}
Example #20
0
void Init() { 
    SDL_Init( SDL_INIT_VIDEO );
    SDL_CreateWindowAndRenderer(SCREENSIZEX, SCREENSIZEY, SDL_WINDOW_SHOWN, &Window, &Renderer );

    int imgFlags = IMG_INIT_PNG;
    if( !( IMG_Init( imgFlags ) & imgFlags ) ) {
      printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 
    }
}
Example #21
0
HardwareLayer::SDLDisplayDriver::SDLDisplayDriver()
{
	SDL_Window* rawWindow = nullptr;
	SDL_Renderer* rawRenderer = nullptr;

	SDL_CreateWindowAndRenderer(Width(), Height(), SDL_WINDOW_SHOWN, &rawWindow, &rawRenderer);

	m_Window = std::unique_ptr<SDL_Window, std::function<void(SDL_Window*)>>(rawWindow, SDL_DestroyWindow);
	m_Renderer = std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer*)>>(rawRenderer, SDL_DestroyRenderer);
}
Example #22
0
int main(int argc, char** argv) {
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
        fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
        exit(1);
    }
    AVFormatContext *pFormatCtx;
    if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0)
        return -1;
    if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
        return -1;
    av_dump_format(pFormatCtx, 0, argv[1], 0);

    AVCodecContext *pCodecCtx = NULL;
    AVCodec *pCodec = NULL;
    int videoStream = -1;

    for (int i = 0; i < pFormatCtx->nb_streams; i++) {
        if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
            videoStream = i;
            break;
        }
    }
    if (videoStream == -1)
        exit(-1);

    pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
    if (pCodec == NULL) {
        fprintf(stderr, "%s\n", "Unsupported codecn");
        exit(-1);
    }

    if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
        exit(-1);

    SDL_Window *surface;
    surface = SDL_CreateWindow(argv[1],
            SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED,
            pCodecCtx->width,
            pCodecCtx->height,
            SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
    if (!surface) {
        fprintf(stderr, "%s\n", "SDL: could not set video mode - exiting");
        exit(1);
    }

    SDL_Texture *texture = NULL;
    SDL_Renderer *renderer = SDL_CreateRenderer(surface, -1, 0);
    SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &surface, &renderer);
    SDL_RenderSetLogicalSize(renderer, pCodecCtx->width, pCodecCtx->height);
    texture = SDL_CreateTexture(renderer,
            SDL_P)

    struct SWSContext *sws_ctx = NULL;
}
Example #23
0
File: drag.c Project: ckeen/KiWi
int main(int argc, char ** argv) {
  
  /* initialize window and renderer */
  SDL_Window * window;
  SDL_Renderer * renderer;
  SDL_Surface * set;
  KW_GUI * gui;
  TTF_Font * font;
  SDL_Rect framegeom;
  KW_Widget * frame, *a;
  int i = 0;  
  
  SDL_Init(SDL_INIT_EVERYTHING);
  SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer);
  SDL_SetRenderDrawColor(renderer, 200, 100, 100, 1);
  TTF_Init();
  
  /* load tileset */
  set = IMG_Load("tileset.png");
  
  /* initialize gui */
  gui = KW_Init(renderer, set);
  font = TTF_OpenFont("Fontin-Regular.ttf", 12);
  KW_SetFont(gui, font);
  frame = NULL;
  framegeom.x = 10, framegeom.y = 10, framegeom.w = 300, framegeom.h = 220;  
  framegeom.x = 50, framegeom.y = 50, framegeom.w = 100, framegeom.h = 100;
  frame = KW_CreateFrame(gui, frame, &framegeom);
  framegeom.x = 10, framegeom.y = 10, framegeom.w = 160, framegeom.h = 120;
  KW_AddWidgetDragHandler(frame, Drag);
  for (i = 0; i < 2; i++) {
    framegeom.x = framegeom.y = i * 10;
    a = KW_CreateButton(gui, frame, "Yay", &framegeom);
    KW_AddWidgetDragStartHandler(a, DragStart);
    KW_AddWidgetDragStopHandler(a, DragStop);
    KW_AddWidgetDragHandler(a, Drag);
  }
  
  while (!SDL_QuitRequested()) {
    SDL_SetRenderDrawColor(renderer, 200, 100, 100, 1);
    SDL_RenderClear(renderer);
    KW_Paint(gui);
    SDL_RenderPresent(renderer);
    SDL_Delay(1);
  }
  
  /* free stuff */
  KW_Quit(gui);
  TTF_CloseFont(font);
  SDL_FreeSurface(set);
  TTF_Quit();
  SDL_Quit();
  
  return 0;
}
Example #24
0
File: renderer.c Project: akydd/sdl
renderer *renderer_new() {
	renderer *new_renderer;
	new_renderer = malloc(sizeof(renderer));

	SDL_Init(SDL_INIT_VIDEO);
	SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &new_renderer->sdl_window, &new_renderer->sdl_renderer);
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	SDL_RenderSetLogicalSize(new_renderer->sdl_renderer, 640, 480);

	return new_renderer;
}
Example #25
0
bool SDLSingleton::InitSystem()
{
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        return 0;
    }

#ifndef WIN32
    if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN, &m_pWindow, &m_pRenderer) < 0)
#else
    if (SDL_CreateWindowAndRenderer(800, 600, 0, &m_pWindow, &m_pRenderer) < 0)
#endif
    {
        return false;
    }

    SDL_GetWindowSize(m_pWindow, &m_winWidth, &m_winHeight);

    // if all this hex scares you, check out SDL_PixelFormatEnumToMasks()!
    m_pGameScreen = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 32,
                                         0,
                                         0,
                                         0,
                                         0);

    if (m_pGameScreen == 0)
    {
        return false;
    }

    m_pGameTexture = SDL_CreateTexture(m_pRenderer,
                                       SDL_PIXELFORMAT_ARGB8888,
                                       SDL_TEXTUREACCESS_STREAMING,
                                       320, 200);

    if (m_pGameTexture == 0)
    {
        return false;
    }

    return true;
}
Example #26
0
int main(int argc, char *argv[]) {
    SDL_Window *window;
    SDL_Renderer *renderer;
    SDL_Event event;
    Uint8 done = 0;

    if (SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer) < 0)
        exit(1);

	Sprite sprite = LoadSprite ("image.png", renderer);
    if (sprite.texture == NULL)
		exit(2);

	SDL_InitSubSystem (SDL_INIT_AUDIO);
	if (Mix_OpenAudio (22050, AUDIO_S16SYS, 2, 2048))
		exit(3);
	Mix_Music *music;
	music = Mix_LoadMUS ("demo.ogg");
	if (!Mix_PlayingMusic ())
		Mix_PlayMusic (music, -1);

	TTF_Font *font;
	SDL_Color colour = { 255, 255, 255 };
	SDL_Surface *text;

	TTF_Init ();

	font = TTF_OpenFont ("arial.ttf", 24);
	if (!font)
		exit (4);

	text = TTF_RenderText_Solid (font, "Hello, World!", colour);

    while (!done) {
        while (SDL_PollEvent (&event)) {
            if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN || event.type == SDL_FINGERDOWN) {
				done = 1;
            }
        }

		SDL_SetRenderDrawColor (renderer, 0xA0, 0xA0, 0xA0, 0xFF);
		SDL_RenderClear (renderer);

		draw (window, renderer, sprite);
		SDL_RenderCopy (renderer, text, NULL, NULL);
	
		SDL_RenderPresent (renderer);
		
		SDL_Delay (10);
    }

    exit (0);
}
Example #27
0
File: renderer.c Project: akydd/sdl
renderer *renderer_new() {
	renderer *new_renderer;
	new_renderer = malloc(sizeof(renderer));

	SDL_Init(SDL_INIT_VIDEO);
	// No fancy scaleing for this tutorial
	SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &new_renderer->sdl_window, &new_renderer->sdl_renderer);
	// SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	// SDL_RenderSetLogicalSize(new_renderer->sdl_renderer, SCREEN_WIDTH, SCREEN_HEIGHT);

	return new_renderer;
}
Example #28
0
int init_sdl(SDL_Window **sdlWindow, SDL_Renderer **sdlRenderer, SDL_Texture **sdlTexture,
             SDL_Surface **screen, int width, int height)
{
    Uint32 flags=0;
    flags |= SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;

    if (SDL_Init(flags) != 0)
    {
        fprintf(stderr,
                "\nUnable to initialize SDL:  %s\n",
                SDL_GetError()
               );
        return -1;
    }
    atexit(SDL_Quit);

    SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN /*| SDL_WINDOW_BORDERLESS*/, sdlWindow, sdlRenderer);
    if (*sdlWindow == NULL || *sdlRenderer == NULL)
    {
        fprintf(stderr, "FCK\n");
        return -1;
    }
    //sdlWindow = *sdlWindow;
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");  // make the scaled rendering look smoother.
    SDL_RenderSetLogicalSize(*sdlRenderer, width, height);

    *screen = SDL_CreateRGBSurface(0, width, height, 32,
                                   0x00FF0000,
                                   0x0000FF00,
                                   0x000000FF,
                                   0xFF000000);
    *sdlTexture = SDL_CreateTexture(*sdlRenderer,
                                    SDL_PIXELFORMAT_RGB888,
                                    SDL_TEXTUREACCESS_STREAMING,
                                    width, height);

    if (*screen == NULL || *sdlTexture == NULL)
    {
        fprintf(stderr, "MAn we have SDL init problems :\\. I couldn't allocate a screen or Texture :\\\n");
        return -1;
    }

    // needs to be more permanent eh!
    char tmpbuf[100];
    sprintf(tmpbuf, PROG_NAME_VERSION_STRING, APP_VERSION);
    SDL_SetWindowTitle(*sdlWindow, tmpbuf);

    Colors::precompute(*screen);

    dblclick::init();

    return 0;
}
Example #29
0
bool GInitContextWindow( const char* title,
		gContextHandles_t& handles )
{
	SDL_Init( SDL_INIT_VIDEO );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, G_API_MAJOR_VERSION );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, G_API_MINOR_VERSION );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, G_API_CONTEXT_PROFILE );

	SDL_CreateWindowAndRenderer( handles.width, handles.height, 
			SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE, 
			&handles.window, &handles.renderer );

	if ( !handles.window ) 
	{
		goto sdl_failure;	
	}

	SDL_SetWindowTitle( handles.window, title );

	handles.context = SDL_GL_CreateContext( handles.window );

	if ( !handles.context )
	{
		goto sdl_failure;	
	}

#ifndef EMSCRIPTEN
	glewExperimental = true;
	GLenum glewErr = glewInit();
	if ( glewErr != GLEW_OK )
	{
		MLOG_ERROR( "Could not initialize GLEW: %s", 
				glewGetErrorString( glewErr ) );
		return false;
	}
#endif

	SDL_RenderPresent( handles.renderer );

	// HACK: error checking is impossible unless this happens;
	// apparently an invalid enumeration exists - possibly
	// in SDL or GLEW's initialization...

	glGetError();

	return true;

sdl_failure:
	MLOG_ERROR( "SDL_Error: %s", SDL_GetError() );
	return false;	
}
Example #30
0
static Sdl ssetup(const int xres, const int yres)
{
    Sdl sdl;
    SDL_Init(SDL_INIT_VIDEO);
    SDL_CreateWindowAndRenderer(xres, yres, 0, &sdl.window, &sdl.renderer);
    SDL_SetWindowTitle(sdl.window, "Gel-1.2");
    // Notice the flip between xres and yres - the renderer is on its side to maximize cache effeciency.
    sdl.canvas = SDL_CreateTexture(sdl.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, yres, xres);
    sdl.xres = xres;
    sdl.yres = yres;
    return sdl;
}