Esempio n. 1
0
ImageSdl::ImageSdl(Image &, Window &window, const std::string &data)
	: m_texture(nullptr, nullptr)
{
	/* Initialize the texture */
	auto rw = SDL_RWFromMem(const_cast<char *>(data.c_str()), data.length());

	if (rw == nullptr) {
		throw std::runtime_error(SDL_GetError());
	}

	m_texture = Handle(IMG_LoadTexture_RW(window.backend().renderer(), rw, true), SDL_DestroyTexture);

	if (m_texture == nullptr) {
		throw std::runtime_error(SDL_GetError());
	}

	/* Store the size */
	int width, height;

	if (SDL_QueryTexture(m_texture.get(), nullptr, nullptr, &width, &height) < 0) {
		throw std::runtime_error(SDL_GetError());
	}

	m_size = Size((unsigned)width, (unsigned)height);
}
Esempio n. 2
0
JSBool webRspGetImg(JSContext *cx, uintN argc, jsval *vp) {
	SDL_Texture *tx = NULL;
	JSObject * object = NULL;
	jsval vl;
	JS_GetProperty(cx,JS_GetGlobalObject(cx),"Image",&vl);
	object = JS_New(cx,JSVAL_TO_OBJECT(vl),0,NULL);
	if(object){
		JSObject *ob = NULL;
		ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp));
		if(ob){
			CURLMsg *msg;
			msg = (CURLMsg*) JS_GetPrivate(cx,ob);
			if(msg){
				rqPrivate *rq = NULL;
				curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq);
				if(rq){
					SDL_RWops* rwop = NULL;
					rwop = SDL_RWFromConstMem(rq->data,rq->size);
					if(rwop){
						tx = IMG_LoadTexture_RW(renderer,rwop,1);
						//tx = IMG_LoadTextureTyped_RW(renderer,rwop,1,"JPEG");
						SDL_RenderCopy(renderer,tx,NULL,NULL);
						if(tx){
							JS_SetPrivate(cx,object,tx);
							imageAddProps(cx,object);
							print("hi\n");
							JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(object));
						}
					}
				}
			}
		}
	}
	return JS_TRUE;
}
void startscreen(SDL_Window *screen,uint *state,uint *grapset,uint *fullscreen) {

	/* Renderer (with VSync, nice !) */
	SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE); // SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
	SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "0");
	SDL_RenderSetLogicalSize(renderer, 256, 192);

	uint exit = 0;
	uint musicplay = 0;

	SDL_Rect srcintro = {0,0,256,192};
	SDL_Rect desintro = {0,0,256,192};

	SDL_Event keyp;

	/* Loading PNG */
	SDL_RWops *rw = SDL_RWFromMem(&_binary_graphics_intro_png_start,
	    (unsigned int)&_binary_graphics_intro_png_end - (unsigned int)&_binary_graphics_intro_png_start);
	SDL_Texture *intro = IMG_LoadTexture_RW(renderer,rw,1);
    rw = SDL_RWFromMem(&_binary_graphics_intromd_png_start,
        (unsigned int)&_binary_graphics_intromd_png_end - (unsigned int)&_binary_graphics_intromd_png_start);
	SDL_Texture *intromd = IMG_LoadTexture_RW(renderer,rw,1);

	/* Load audio */
    rw = SDL_RWFromMem(&_binary_sounds_MainTitleN_ogg_start,
        (unsigned int)&_binary_sounds_MainTitleN_ogg_end - (unsigned int)&_binary_sounds_MainTitleN_ogg_start);
	Mix_Music *music = Mix_LoadMUS_RW(rw,1);

	while (exit != 1) {

		/* Cleaning the renderer */
		SDL_RenderClear(renderer);

		/* Put image on renderer */
		if (*grapset == 0)
			SDL_RenderCopy(renderer, intro, &srcintro, &desintro);
		else
			SDL_RenderCopy(renderer, intromd, &srcintro, &desintro);

		/* Flip ! */
		SDL_RenderPresent(renderer);

		/* Play music if required */
		if (musicplay == 0) {
			musicplay = 1;
			Mix_PlayMusic(music, 0);
		}

		/* Check keyboard */
		if ( SDL_PollEvent(&keyp) ) {
			if (keyp.type == SDL_KEYDOWN) { /* Key pressed */
				if (keyp.key.keysym.sym == SDLK_c) { /* Change graphic set */
					if (*grapset == 0)
						*grapset = 1;
					else
						*grapset = 0;
				}
				if (keyp.key.keysym.sym == SDLK_i) { /* Show instructions */
					if (srcintro.y == 0)
						srcintro.y = 192;
					else {
						srcintro.y = 0;
						musicplay = 0;
					}
				}
				if (keyp.key.keysym.sym == SDLK_SPACE) { /* Start game */
					*state = 1;
					exit = 1;
				}
			}
            if (keyp.type == SDL_CONTROLLERBUTTONDOWN) { /* Game controller button pressed */
                if (keyp.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { /* Change graphic set */
                    if (*grapset == 0)
                        *grapset = 1;
                    else
                        *grapset = 0;
                }
                if (keyp.cbutton.button == SDL_CONTROLLER_BUTTON_A || keyp.cbutton.button == SDL_CONTROLLER_BUTTON_B) { /* Show instructions */
                    if (srcintro.y == 0)
                        srcintro.y = 192;
                    else {
                        srcintro.y = 0;
                        musicplay = 0;
                    }
                }
                if (keyp.cbutton.button == SDL_CONTROLLER_BUTTON_START) { /* Start game */
                    *state = 1;
                    exit = 1;
                }
            }
		}

	}

	/* Cleaning */
	SDL_DestroyTexture(intro);
	SDL_DestroyTexture(intromd);
	SDL_DestroyRenderer(renderer);

}
Esempio n. 4
-1
void gameover (SDL_Window *screen,uint *state) {

	SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE); // SDL_RENDERER_PRESENTVSYNC);
	//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	//SDL_RenderSetLogicalSize(renderer, 256, 192);
	SDL_SetRenderDrawColor(renderer,0,0,0,255);

	SDL_RWops *rw = SDL_RWFromMem(&_binary_graphics_gameover_png_start,
        (unsigned int)&_binary_graphics_gameover_png_end - (unsigned int)&_binary_graphics_gameover_png_start);
	SDL_Texture *gameover = IMG_LoadTexture_RW(renderer,rw,1);

    rw = SDL_RWFromMem(&_binary_sounds_GameOverV2N_ogg_start,
        (unsigned int)&_binary_sounds_GameOverV2N_ogg_end - (unsigned int)&_binary_sounds_GameOverV2N_ogg_start);
	Mix_Music *bso = Mix_LoadMUS_RW(rw,1);

	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer,gameover,NULL,NULL);

	/* Flip */
	SDL_RenderPresent(renderer);
	Mix_PlayMusic(bso, 0);

	/* Wait */
	sleep(12);

	/* Cleaning */
	Mix_FreeMusic (bso);
	SDL_DestroyTexture(gameover);
	SDL_DestroyRenderer(renderer);

	*state = 0;

}