Exemplo n.º 1
0
void
DrawLines(SDL_Window * window)
{
    int i;
    int x1, y1, x2, y2;
    int window_w, window_h;

    /* Query the sizes */
    SDL_GetWindowSize(window, &window_w, &window_h);

    SDL_SetRenderDrawBlendMode(blendMode);
    for (i = 0; i < num_lines; ++i) {
        SDL_SetRenderDrawColor(255, 255, 255, 255);

        if (i == -1) {
            SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
            SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
            SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
            SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
        } else {
            SDL_RenderDrawLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h);
        }
    }
    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
}
Exemplo n.º 2
0
void PauseMenu::Draw(SDL_Renderer* rR) {
	SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(rR, 4, 4, 4, 235);
	SDL_RenderFillRect(rR, &rPause);
	SDL_SetRenderDrawColor(rR, 255, 255, 255, 255);
	rPause.x += 1;
	rPause.y += 1;
	rPause.h -= 2;
	rPause.w -= 2;
	SDL_RenderDrawRect(rR, &rPause);
	rPause.x -= 1;
	rPause.y -= 1;
	rPause.h += 2;
	rPause.w += 2;

	for(unsigned int i = 0; i < lMO.size(); i++) {
		if(i == activeMenuOption) {
			CCFG::getText()->DrawCenterX(rR, lMO[i]->getText(), lMO[i]->getYPos(), 16, 255, 255, 255);
		} else {
			CCFG::getText()->DrawCenterX(rR, lMO[i]->getText(), lMO[i]->getYPos(), 16, 90, 90, 90);
		}
	}

	SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_NONE);
	CCore::getMap()->setBackgroundColor(rR);
}
Exemplo n.º 3
0
static void drawMain(void)
{
	SDL_Rect r;

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
	SDL_RenderFillRect(app.renderer, NULL);
	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);

	r.w = 500;
	r.h = 600;
	r.x = (SCREEN_WIDTH / 2) - r.w / 2;
	r.y = (SCREEN_HEIGHT / 2) - r.h / 2;

	SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
	SDL_RenderFillRect(app.renderer, &r);
	SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
	SDL_RenderDrawRect(app.renderer, &r);

	drawText(SCREEN_WIDTH / 2, 70, 28, TA_CENTER, colors.white, OPTIONS_TEXT);

	SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
	SDL_RenderDrawLine(app.renderer, r.x, 120, r.x + r.w, 120);

	drawWidgets("options");

	limitTextWidth(r.w - 100);
	drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, RESOLUTION_TEXT);
	limitTextWidth(0);
}
Exemplo n.º 4
0
void drawWidgets(const char *group)
{
	Widget *w;
	
	drawingWidgets = 1;
	
	for (w = head.next; w != NULL ; w = w->next)
	{
		if (w->visible && strcmp(w->group, group) == 0)
		{
			SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
			SDL_RenderFillRect(app.renderer, &w->rect);
			
			if (w == selectedWidget)
			{
				SDL_SetRenderDrawColor(app.renderer, 64, 128, 200, SDL_ALPHA_OPAQUE);
				SDL_RenderFillRect(app.renderer, &w->rect);
				SDL_SetRenderDrawColor(app.renderer, 128, 192, 255, SDL_ALPHA_OPAQUE);
				SDL_RenderDrawRect(app.renderer, &w->rect);
			}
			else
			{
				SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE);
				SDL_RenderDrawRect(app.renderer, &w->rect);
			}
			
			switch (w->type)
			{
				case WT_BUTTON:
					SDL_RenderDrawRect(app.renderer, &w->rect);
					drawText(w->rect.x + (w->rect.w / 2), w->rect.y + 2, 20, TA_CENTER, colors.white, w->text);
					break;
					
				case WT_SELECT:
					drawText(w->rect.x + 10, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
					drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->currentOption]);
					
					if (w->currentOption != 0)
					{
						blit(optionsLeft, w->rect.x - 24, w->rect.y + 16, 1);
					}
					
					if (w->currentOption != w->numOptions - 1)
					{
						blit(optionsRight, w->rect.x + w->rect.w + 24, w->rect.y + 16, 1);
					}
					
					break;
			}

			if (!w->enabled)
			{
				SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
				SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 192);
				SDL_RenderFillRect(app.renderer, &w->rect);
				SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
			}
		}
	}
}
Exemplo n.º 5
0
Arquivo: draw.c Projeto: nnesse/tbftss
void drawCircle(int cx, int cy, int radius, int r, int g, int b, int a)
{
    int x = radius;
    int y = 0;
    int radiusError = 1 - x;

    SDL_SetRenderDrawColor(app.renderer, r, g, b, a);
    SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);

    while (x >= y)
    {
        SDL_RenderDrawPoint(app.renderer, x + cx,  y + cy);
        SDL_RenderDrawPoint(app.renderer, y + cx,  x + cy);
        SDL_RenderDrawPoint(app.renderer,-x + cx,  y + cy);
        SDL_RenderDrawPoint(app.renderer,-y + cx,  x + cy);
        SDL_RenderDrawPoint(app.renderer,-x + cx, -y + cy);
        SDL_RenderDrawPoint(app.renderer,-y + cx, -x + cy);
        SDL_RenderDrawPoint(app.renderer, x + cx, -y + cy);
        SDL_RenderDrawPoint(app.renderer, y + cx, -x + cy);

        y++;

        if (radiusError < 0)
        {
            radiusError += 2 * y + 1;
        }
        else
        {
            x--;
            radiusError += 2 * (y - x) + 1;
        }
    }

    SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
}
Exemplo n.º 6
0
void meh_widget_rect_render(Window* window, const WidgetRect* rect) {
	g_assert(rect != NULL);
	g_assert(window != NULL);

	SDL_SetRenderDrawColor(window->sdl_renderer, rect->r.value, rect->g.value, rect->b.value, rect->a.value);

	if (rect->a.value != SDL_ALPHA_OPAQUE) {
		SDL_SetRenderDrawBlendMode(window->sdl_renderer, SDL_BLENDMODE_BLEND);
	} else {
		SDL_SetRenderDrawBlendMode(window->sdl_renderer, SDL_BLENDMODE_NONE);

	}

	SDL_Rect sdl_rect = {
		meh_window_convert_width(window, rect->x.value),
		meh_window_convert_height(window, rect->y.value),
		meh_window_convert_width(window, rect->w.value),
		meh_window_convert_height(window, rect->h.value)
	};

	if (rect->filled) {
		SDL_RenderFillRect(window->sdl_renderer, &sdl_rect);
	} else {
		SDL_RenderDrawRect(window->sdl_renderer, &sdl_rect);
	}
}
Exemplo n.º 7
0
void DrawDeath(SDL_Renderer *r)
{
	float end = GetGameOverTime();
	if (g_scrub->mSpentTime < end)
		return;

	static bool firstDeath = true;
	if (firstDeath) {
		g_world->myAudioManager.PlaySound("assets/audio/failed.mp3", false);
		firstDeath = false;
		isDead = true;
	}


	SDL_Rect rect;
	rect.x = 0;
	rect.y = 0;
	rect.w = RES_X;
	rect.h = RES_Y;
	SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_MOD);
	SDL_SetRenderDrawColor(r, 128, 128, 128, 128);
	SDL_RenderFillRect(r, &rect);

	SDL_Rect rc;
	SDL_QueryTexture(deathTexture, NULL, NULL, &rc.w, &rc.h);

	rc.x = 800 - rc.w / 2;
	rc.y = 450 - rc.h / 2;

	SDL_RenderCopy(r, deathTexture, nullptr, &rc);

	SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_ADD);
	SDL_SetRenderDrawColor(r, 255, 255, 255, 255);
	SDL_RenderDrawRect(r, &rc);
}
Exemplo n.º 8
0
static void
DrawRectLineIntersections(SDL_Window * window)
{
    int i, j, window_w, window_h;

    /* Query the sizes */
    SDL_GetWindowSize(window, &window_w, &window_h);

    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);

    for (i = 0; i < num_rects; i++)
        for (j = 0; j < num_lines; j++) {
            int x1, y1, x2, y2;
            SDL_Rect r;

            r = rects[i];
            x1 = lines[j].x;
            y1 = lines[j].y;
            x2 = lines[j].w;
            y2 = lines[j].h;

            if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
                SDL_SetRenderDrawColor(0, 255, 55, 255);
                SDL_RenderDrawLine(x1, y1, x2, y2);
            }
        }

    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
}
Exemplo n.º 9
0
void SDLRenderer::setDrawColor(const Color& color) {
    if (color.a < 255) {
        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
    } else {
        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
    }
    SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
}
Exemplo n.º 10
0
void ScenePatch(){
	bool quit = false;
	SDL_Event event;

	Sprite *bgi = new Sprite("resource\\bgi_patcher.jpg",1,1);
	Sprite *title = new Sprite("resource\\title.png",1,1);

	FONT gulim;

	float progress_total = 50;
	float progress_current = 30;

	gulim.InitFont("c:\\windows\\fonts\\gulim.ttc",12);
	gulim.SetColor(255,255,255);
	gulim.SetStyle(TTF_STYLE_BOLD);

	while(!quit){
		while(SDL_PollEvent(&event)){
			switch(event.type){
			case SDL_QUIT:
				break;
			}
		}
		{
			SDL_RenderClear(renderer);

			bgi->Draw(0,0,480,272);
			title->Draw(20,20,440,170);


			SDL_Rect rtProgressTotalFrame = {20,200,440,25};
			SDL_Rect rtProgressCurrentFrame = {20,235,440,25};
			SDL_Rect rtProgressTotal = {25,205,progress_total * 4.4,15};
			SDL_Rect rtProgressCurrent = {25,240,progress_current * 4.4,15};

			SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_NONE);
			SDL_SetRenderDrawColor(renderer,64,64,64,255);
			SDL_RenderFillRect(renderer,&rtProgressTotalFrame);
			SDL_RenderFillRect(renderer,&rtProgressCurrentFrame);

			SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
			SDL_SetRenderDrawColor(renderer,64,255,64,196);
			SDL_RenderFillRect(renderer,&rtProgressTotal);
			SDL_RenderFillRect(renderer,&rtProgressCurrent);

			gulim.Draw(renderer,"전체 진행률",25,190);
			gulim.Draw(renderer,"현재 진행률",25,225);

			gulim.Draw(renderer,"Tank Online Patcher",343,258);

			SDL_RenderPresent(renderer);
		}

		SDL_Delay(1);
	}

	delete bgi;
}
Exemplo n.º 11
0
void Simulation::Render()
{
    SDL_Renderer *renderer = Game::getGlobalGame()->getRenderer();

    Game::getGlobalGame()->setBackgroundColor(0, 0, 0);

    // Render do Fundo
//    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD);
    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);

    drawBG(background[0], bgOffsetX, bgOffsetY, -0.1, renderer);
    drawBG(background[1], bgOffsetX, bgOffsetY, -0.13, renderer);
    drawBG(background[2], bgOffsetX, bgOffsetY, -0.2, renderer);
    drawBG(background[3], bgOffsetX, bgOffsetY, -0.28, renderer);
//    background[0]->DrawImage(bgOffsetX*0.10, bgOffsetY*0.10, renderer);
//    background[1]->DrawImage(bgOffsetX*0.13, bgOffsetY*0.13, renderer);
//    background[2]->DrawImage(bgOffsetX*0.20, bgOffsetY*0.20, renderer);
//    background[3]->DrawImage(bgOffsetX*0.28, bgOffsetY*0.28, renderer);

//    background->DrawImage(bgOffsetX, bgOffsetY, renderer);
//    background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(),
//                          bgOffsetY + Game::getGlobalGame()->getHeight(), renderer);
//
//    background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(), bgOffsetY, renderer);
//    background->DrawImage(bgOffsetX, bgOffsetY + Game::getGlobalGame()->getHeight(), renderer);

    //Just TESTING
    SDL_SetRenderTarget(renderer, renderCombat);
        // Limpar textura
        SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND);
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
        SDL_RenderClear(renderer);

        SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE);
        SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND);

        simulationWorld->render();
    SDL_SetRenderTarget(renderer, 0);

    // Renderizar imagem de combate na tela
    SDL_Rect rect;
    rect.x = -camera->getX();  rect.w = 2048;
    rect.y = -camera->getY();  rect.h = 2048;

    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE);
    SDL_RenderCopy( renderer, renderCombat, 0, &rect);

    if(selectedUnit)
    {
        filledCircleRGBA( renderer, selectedUnit->getAvgX(), selectedUnit->getAvgY(), 64, 0, 0, 255, 128 );
    }
}
Exemplo n.º 12
0
void drawControls(void)
{
    int i;
    SDL_Rect r;

    SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
    SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
    SDL_RenderFillRect(app.renderer, NULL);
    SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);

    r.w = 800;
    r.h = 650;
    r.x = (SCREEN_WIDTH / 2) - r.w / 2;
    r.y = (SCREEN_HEIGHT / 2) - r.h / 2;

    SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
    SDL_RenderFillRect(app.renderer, &r);
    SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
    SDL_RenderDrawRect(app.renderer, &r);

    drawText(SCREEN_WIDTH / 2, 50, 28, TA_CENTER, colors.white, CONTROLS_TEXT);

    SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
    SDL_RenderDrawLine(app.renderer, r.x, r.y + 65, r.x + r.w, r.y + 65);

    r.x += 25;
    r.y = 125;

    for (i = 0 ; i < CONTROL_MAX ; i++)
    {
        drawText(r.x, r.y + 2, 20, TA_LEFT, colors.white, controlName[i]);

        controlWidget[i]->rect.x = r.x + 175;
        controlWidget[i]->rect.y = r.y;

        r.y += 65;

        if (r.y > 500)
        {
            r.y = 125;
            r.x += 400;
        }
    }

    limitTextWidth(r.w - 100);
    drawText(SCREEN_WIDTH / 2, 525, 16, TA_CENTER, colors.white, HELP_TEXT);
    drawText((SCREEN_WIDTH / 2) - 50, 560, 16, TA_RIGHT, colors.white, BACKSPACE_TEXT);
    drawText((SCREEN_WIDTH / 2) + 50, 560, 16, TA_LEFT, colors.white, ESCAPE_TEXT);
    limitTextWidth(0);

    drawWidgets("controls");
}
Exemplo n.º 13
0
void Particle::render(const flat2d::RenderData* data) const
{
	flat2d::Camera *cam = data->getCamera();

	SDL_Renderer *renderer = data->getRenderer();
	setRenderDrawColor(renderer);
	SDL_Rect box = { cam->getScreenXposFor(entityProperties.getXpos()),
		cam->getScreenYposFor(entityProperties.getYpos()),
		entityProperties.getWidth(), entityProperties.getHeight() };

	SDL_SetRenderDrawBlendMode(renderer, blendMode);
	SDL_RenderFillRect( renderer, &box );
	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
}
Exemplo n.º 14
0
/**
 * @brief Test to see if we can vary the blend mode. Helper function.
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
 * http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawBlendMode
 */
static int
_hasBlendModes (void)
{
   int fail;
   int ret;
   SDL_BlendMode mode;

   fail = 0;

   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   if (!_isSupported(ret))
      fail = 1;
   ret = (mode != SDL_BLENDMODE_BLEND);
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   if (!_isSupported(ret))
      fail = 1;
   ret = (mode != SDL_BLENDMODE_ADD);
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD );
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   if (!_isSupported(ret))
      fail = 1;
   ret = (mode != SDL_BLENDMODE_MOD);
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   if (!_isSupported(ret))
      fail = 1;
   ret = (mode != SDL_BLENDMODE_NONE);
   if (!_isSupported(ret))
      fail = 1;

   return !fail;
}
bool j1Render::DrawCircle(int x, int y, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	int result = -1;
	SDL_Point points[360];

	float factor = (float)M_PI / 180.0f;

	for(uint i = 0; i < 360; ++i)
	{
		points[i].x = (int)(x + radius * cos(i * factor));
		points[i].y = (int)(y + radius * sin(i * factor));
	}

	result = SDL_RenderDrawPoints(renderer, points, 360);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
Exemplo n.º 16
0
Arquivo: util.c Projeto: autrimpo/imv
void imv_printf(SDL_Renderer *renderer, TTF_Font *font, int x, int y,
                SDL_Color *fg, SDL_Color *bg, const char *fmt, ...)
{
  char line[512];
  va_list args;
  va_start(args, fmt);
  vsnprintf(line, sizeof(line), fmt, args);

  SDL_Surface *surf = TTF_RenderUTF8_Blended(font, &line[0], *fg);
  SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, surf);

  SDL_Rect tex_rect = {0,0,0,0};
  SDL_QueryTexture(tex, NULL, NULL, &tex_rect.w, &tex_rect.h);
  tex_rect.x = x;
  tex_rect.y = y;

  /* draw bg if wanted */
  if(bg->a > 0) {
    SDL_SetRenderDrawColor(renderer, bg->r, bg->g, bg->b, bg->a);
    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
    SDL_RenderFillRect(renderer, &tex_rect);
  }
  SDL_RenderCopy(renderer, tex, NULL, &tex_rect);

  SDL_DestroyTexture(tex);
  SDL_FreeSurface(surf);
  va_end(args);
}
bool j1Render::DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool filled, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	SDL_Rect rec(rect);
	if(use_camera)
	{
		rec.x = (int)(camera.x + rect.x * scale);
		rec.y = (int)(camera.y + rect.y * scale);
		rec.w *= scale;
		rec.h *= scale;
	}

	int result = (filled) ? SDL_RenderFillRect(renderer, &rec) : SDL_RenderDrawRect(renderer, &rec);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
Exemplo n.º 18
0
void video_start_window( )
{
	if ( SDL_VideoInit(video_options.driver) ) {
		fatal( "%s", SDL_GetError() );
	}
	video_window = SDL_CreateWindow(
		video_options.title,
		video_options.position.x,
		video_options.position.y,
		video_options.size.w,
		video_options.size.h,
		SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI );
	if ( video_window == NULL ) {
		fatal( "%s", SDL_GetError() );
	}
	video_renderer = SDL_CreateRenderer( video_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
	if ( video_renderer == NULL ) {
		fatal( "%s", SDL_GetError() );
	}
	SDL_SetRenderDrawBlendMode( video_renderer, SDL_BLENDMODE_BLEND );
	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
	SDL_RenderSetLogicalSize(
		video_renderer,
		video_options.logical_size.w,
		video_options.logical_size.h );
	SDL_SetWindowGrab( video_window, video_options.grab_input );
	if ( video_options.set_mode ) {
		SDL_SetWindowDisplayMode( video_window, &video_options.mode );
	} else {
		SDL_SetWindowDisplayMode( video_window, NULL );
	}
	SDL_SetWindowFullscreen( video_window, video_options.fullscreen );
}
void PromptOverlay::Draw()
{
    pDarkeningImage->Draw(Vector2(0, 0), Color(fadeOpacity * 0.75, 1, 1, 1));

    if (allowsTextEntry)
    {
        Vector2 textEnteredPosition = Vector2((gScreenWidth - pTextEntryFont->GetWidth(textEntered)) / 2, (gScreenHeight - pTextEntryFont->GetLineHeight()) / 2 + yOffset);
        pTextEntryFont->Draw(textEntered, textEnteredPosition, Color(fadeOpacity, 1, 1, 1));

        if (TextInputHelper::GetIsCaretShowing())
        {
            SDL_Rect rect = { (int)(textEnteredPosition.GetX() + pTextEntryFont->GetWidth(textEntered.substr(0, TextInputHelper::GetCaretPosition()))), (int)textEnteredPosition.GetY(), 2, (int)pTextEntryFont->GetLineHeight() };
            SDL_SetRenderDrawColor(gpRenderer, 255, 255, 255, (Uint8)(fadeOpacity * 255));
            SDL_SetRenderDrawBlendMode(gpRenderer, SDL_BLENDMODE_BLEND);
            SDL_RenderFillRect(gpRenderer, &rect);
        }
    }

    int textLineTop = gScreenHeight / 2 - pTextFont->GetLineHeight() * (1 + headerTextLines.size()) - (allowsTextEntry ? 2 * pTextEntryFont->GetLineHeight() / 3 : 0) + yOffset;

    for (unsigned int i = 0; i < headerTextLines.size(); i++)
    {
        pTextFont->Draw(headerTextLines[i], Vector2((gScreenWidth - pTextFont->GetWidth(headerTextLines[i])) / 2, textLineTop + pTextFont->GetLineHeight() * i), Color(fadeOpacity, 1, 1, 1));
    }

    for (unsigned int i = 0; i < buttonList.size(); i++)
    {
        buttonList[i]->Draw(fadeOpacity);
    }
}
Exemplo n.º 20
0
void Renderer::createRenderer(std::string name, int width, int height, Uint32 flags) {
	window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
    SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
	renderFrame = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING | SDL_TEXTUREACCESS_TARGET, width, height);
	screenSize = {0, 0, width, height};
}
Exemplo n.º 21
0
bool ModuleRender::DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool filled, bool use_camera)
{
	bool ret = true;

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	SDL_Rect rec(rect);
	if(use_camera)
	{
		rec.x = (int)(camera.x + rect.x * SCREEN_SIZE);
		rec.y = (int)(camera.y + rect.y * SCREEN_SIZE);
		rec.w *= SCREEN_SIZE;
		rec.h *= SCREEN_SIZE;
	}

	int result = (filled) ? SDL_RenderFillRect(renderer, &rec) : SDL_RenderDrawRect(renderer, &rec);
	
	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
Exemplo n.º 22
0
void setup(){
	window          = SDL_CreateWindow( "SDL Tutorial",   SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
	render        	= SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
	SDL_UpdateWindowSurface( window );

	pot = new double[ nx*ny ];
	psi = new double[ nx*ny ];

	double sigma2 = 0.0002;
	for (int iy=0; iy<ny; iy++){
		int i0y = iy*nx; 
		for (int ix=0; ix<nx; ix++){
			int ixy = i0y + ix; 
			double x  = ix - (nx>>1);
			double y  = iy - (ny>>1);
			double r2 = x*x + y*y;
			pot[ ixy ] = exp( -r2*sigma2 );
			psi[ ixy ] = randf() - 0.5;
			if( (iy == 0)||(iy == ny-1)||(ix == 0)||(ix == nx-1) ){
				psi[ ixy ] = 0;
			}
		}
	}

	tempSurf  = SDL_CreateRGBSurface(0,SCREEN_WIDTH,SCREEN_HEIGHT,32,0,0,0,0 );
	//setPixels_array( tempSurf, 0, 0, nx, ny,     ny, pot, 1.0 );
	tempTex   = SDL_CreateTextureFromSurface( render, tempSurf  );
	SrcR.x  = 0; SrcR.y  = 0; SrcR.w  = tempSurf->w; SrcR.h  = tempSurf->h;
	DestR.x = 0; DestR.y = 0; DestR.w = tempSurf->w; DestR.h = tempSurf->h;
	SDL_SetRenderDrawBlendMode( render, SDL_BLENDMODE_BLEND );
	
}
Exemplo n.º 23
0
void Console::Draw(SDL_Renderer* rR) {
	if(vPrint.size() > 0) {
		SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_BLEND);
		SDL_SetRenderDrawColor(rR, 4, 4, 4, 128);
		SDL_RenderFillRect(rR, &rRect);
		SDL_SetRenderDrawColor(rR, 255, 255, 255, 128);
		SDL_RenderDrawRect(rR, &rRect);
		SDL_SetRenderDrawColor(rR, 255, 255, 255, 255);
	
		for(int i = vPrint.size() - 1, j = 0; i >= 0; i--, j++) {
			CCFG::getText()->Draw(rR, vPrint[i], rRect.x + rRect.w - 5 - CCFG::getText()->getTextWidth(vPrint[i], 8), rRect.y + rRect.h - 5 - 8*(j+1) - 4*j, 8);
		}

		SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_NONE);
	}
}
Exemplo n.º 24
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);
}
Exemplo n.º 25
0
void debug_hud_render(DebugHud* self, SDL_Renderer* renderer, int x, int y) {
    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 127);
    SDL_Rect bg;
    bg.x = x;
    bg.y = y;
    bg.w = 200;
    bg.h = self->count * (self->ptSize + 2) + 10;
    SDL_RenderFillRect(renderer, &bg);

    int wx = x + 5;
    int wy = y + 5;
    
    for (u32 i = 0; i < self->count; ++i) {
        DebugHudWatch* watch = &self->watches[i];
        
        if (!watch->texture) {
            continue;
        }
        
        SDL_Rect r;
        r.x = wx;
        r.y = wy;
        SDL_QueryTexture(watch->texture, NULL, NULL, &r.w, &r.h);
        SDL_RenderCopy(renderer, watch->texture, NULL, &r);

        wy += self->ptSize + 2;
    }
}
Exemplo n.º 26
0
static void render(void) {
	SDL_SetTextureAlphaMod(title_rotate[rotate_index].texture, 0xFF * brightness);
	SDL_SetRenderDrawColor(display.renderer, 0x20, 0x20, 0x20, 0x20);
	SDL_RenderClear(display.renderer);
	SDL_SetRenderDrawBlendMode(display.renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(display.renderer, 0xFF, 0xFF, 0xFF, 0x20);

	draw_text_splat(&title_rotate[rotate_index], -1, 0);
	draw_sprite(panel_timer, 16, 28);
	timer_blit(ticks_countup, REFERENCE_WIDTH - 22, 32);
	draw_text_splat(&elapsed_time, -1, 56);
	
	SDL_RenderDrawLine(display.renderer, 0, 80, REFERENCE_WIDTH, 80);
	
	draw_text_splat(&achievements, -1, 81);
	
	if (achievement_index != -1) {
		draw_sprite(panel_achievement, 0, 106);
		draw_sprite(achievement_index, 9, 114);
		draw_text_splat(&ach_title[achievement_index], 48, 130 - (ach_title[achievement_index].source_rect.h / 2));
		draw_text_splat(&ach_desc[achievement_index], 4, 152);
	} else {
		draw_text_splat(&achievements_none, -1, 130);
	}
	
	SDL_RenderDrawLine(display.renderer, 0, 224, REFERENCE_WIDTH, 224);
	if (achievement_count > 1) {
		draw_text_splat(&achievements_more, -1, 232);
		draw_sprite(sui_arrow_left, 0, 226);
		draw_sprite(sui_arrow_right, REFERENCE_WIDTH - 32, 226);
	}
}
Exemplo n.º 27
0
void setup(){
	window          = SDL_CreateWindow( "SDL Tutorial",   SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
	render        	= SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
	SDL_UpdateWindowSurface( window );

	tempSurf        = SDL_CreateRGBSurface(0,SCREEN_WIDTH,SCREEN_HEIGHT,32,0,0,0,0 );
	//setPixelsFunction( tempSurf, 0, 0, tempSurf->w,    tempSurf->h, &harmonic );
	//setPixelsFunction( tempSurf, 0, 0, tempSurf->w,    tempSurf->h, &rosenbrok );
	//setPixelsFunction( tempSurf, 0, 0, tempSurf->w,    tempSurf->h, &cosValey );
	setPixelsFunction( tempSurf, 0, 0, tempSurf->w,    tempSurf->h, &spiral );
	//setPixelsFunction( tempSurf, 0, 0, tempSurf->w,    tempSurf->h, -2.0,-2.0, 2.0, 2.0, &mandelbort );

	tempTex   = SDL_CreateTextureFromSurface( render, tempSurf  );

	SrcR.x  = 0; SrcR.y  = 0; SrcR.w  = tempSurf->w; SrcR.h  = tempSurf->h;
	DestR.x = 0; DestR.y = 0; DestR.w = tempSurf->w; DestR.h = tempSurf->h;

	SDL_RenderCopy( render, tempTex, &SrcR, &DestR);

	//opt1 = new OptimizerRandom( 2, 0.05, &fittnessFunc_rosenbrok );
	//opt1->xBest[0] = 0.7;
	//opt1->xBest[1] = -0.3;

	//opt1 = new OptimizerRandom( 2, xBest, dxMax, &fittnessFunc_rosenbrok );
	//opt1 = new OptimizerRandom_2( 2, xBest, dxMax, 0.7, 0.5, &fittnessFunc_rosenbrok );
	opt1 = new OptimizerRandom_3( 2, xBest, dxMax, 0.7, 1.2, &fittnessFunc_rosenbrok );

	SDL_SetRenderDrawBlendMode( render, SDL_BLENDMODE_BLEND );
	
}
Exemplo n.º 28
0
void render(void) {
	SDL_SetRenderDrawColor(display.renderer, 0x20, 0x20, 0x20, 0xFF);
	SDL_RenderClear(display.renderer);
	draw_text_splat(&title_1, -1, 25);
	draw_text_splat(&title_2, -1, 35);
	
	SDL_SetTextureAlphaMod(rotator[rotate_index].texture, 0xFF * brightness);
	draw_text_splat(&rotator[rotate_index], -1, REFERENCE_HEIGHT - 24);
	
	SDL_SetRenderDrawBlendMode(display.renderer, SDL_BLENDMODE_BLEND);
	for (int x = 0; x < REFERENCE_WIDTH; x += 32) {
		SDL_Rect dest_rect = { x, 128, 32, 32 };
		SDL_RenderCopy(display.renderer, backlight->texture, &backlight->src_rect[0], &dest_rect);
	}
	sprite_t *dude_sprite = sprite_thing_get(dude.type);
	SDL_Rect dest_rect = {
		position,
		144,
		dude_sprite->src_rect[dude.current_frame].w,
		dude_sprite->src_rect[dude.current_frame].h
	};
	SDL_RenderCopy(display.renderer, dude_sprite->texture, &dude_sprite->src_rect[dude.current_frame], &dest_rect);
	for (int x = 0; x < REFERENCE_WIDTH; x += 32) {
		SDL_Rect fore_rect = { x, 128, 32, 32 };
		SDL_Rect bott_rect = { x, 160, 32, 32 };
		SDL_RenderCopy(display.renderer, foreground->texture, &foreground->src_rect[0], &fore_rect);
		SDL_RenderCopy(display.renderer, bottom->texture, &bottom->src_rect[0], &bott_rect);
	}
}
Exemplo n.º 29
0
void Lightning::prepareForRendering(SDL_Renderer *renderer)
{
    SDL_SetRenderTarget(renderer, NULL);
    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
    SDL_SetRenderDrawColor(renderer, 128, 128, 128, 255);

}
Exemplo n.º 30
0
 TemporaryOffscreenRenderMode(SDL_Renderer * master)
 {
     renderer = master;
     texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, Sys::shape.w, Sys::shape.h);
     SDL_SetRenderTarget(renderer, texture);
     SDL_SetTextureBlendMode( texture, SDL_BLENDMODE_BLEND );
     
     SDL_BlendMode temp;
     SDL_GetRenderDrawBlendMode( renderer, &temp );
     
     SDL_SetRenderDrawBlendMode( renderer, SDL_BLENDMODE_NONE );
     SDL_SetRenderDrawColor( renderer, 127, 0, 255, 0 ); // RGBs are to detect improper blending
     SDL_RenderFillRect( renderer, &shape );
     
     SDL_SetRenderDrawBlendMode( renderer, temp );
 }