Exemple #1
0
//Render Manager.
void CConsole::Render()
{
	if (! (m_bVisible || m_bToggle) ) return;

	CFont font(CONSOLE_FONT);
	font.Bind();

	// animation: slide in from top of screen
	const float MaxY = m_fHeight;
	const float DeltaY = (1.0f - m_fVisibleFrac) * MaxY;

	glPushMatrix();

	glTranslatef(m_fX, m_fY + DeltaY, 0.0f); //Move to window position

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	DrawWindow();
	DrawHistory();
	DrawBuffer();

	glDisable(GL_BLEND);

	glPopMatrix();
}
Exemple #2
0
static inline bool LatestVersion(int *major, int *minor, int *current_line) {
	u32 http_status = 0;
	u8* outbuf = NULL;
	u32 filesize;
	int line = *current_line;

	PrintFormat(DEFAULT_SIZE, BLACK, MENU_POS_X, MENU_POS_Y + 20*line, Downloads[DOWNLOAD_VERSION].text);
	UpdateScreen();
	line++;
	if(!http_request(Downloads[DOWNLOAD_VERSION].url, Downloads[DOWNLOAD_VERSION].max_size)) {
		PrintFormat(DEFAULT_SIZE, BLACK, MENU_POS_X, MENU_POS_Y + 20*line, "Failed to retrieve version");
		UpdateScreen();
		*current_line = line;
		return false;
	}
	

	http_get_result(&http_status, &outbuf, &filesize);
	
	if (((int)*outbuf & 0xF0000000) == 0xF0000000) 
	{
		if (outbuf != NULL) free(outbuf);
		*current_line = line;
		return false;
	}
	sscanf((char*)outbuf, " #ifndef %*s #define %*s #define NIN_MAJOR_VERSION %i #define NIN_MINOR_VERSION %i", major, minor);
	gprintf("major = %i, minor = %i\r\n", *major, *minor);
	if (outbuf != NULL) free(outbuf);
	if ((*major <= NIN_MAJOR_VERSION) && (*minor <= NIN_MINOR_VERSION)) {
		bool still_download = true;
		PrintFormat(DEFAULT_SIZE, BLACK, MENU_POS_X, MENU_POS_Y + 20*line, "You already have the latest version");
		line++;
		PrintFormat(DEFAULT_SIZE, BLACK, MENU_POS_X, MENU_POS_Y + 20*line, "Download anyway? (A: Yes, B: No)");
		line++;
		UpdateScreen();
		while(true) {
			DrawBuffer();
			FPAD_Update();
			if (FPAD_Cancel(0)) {
				gprintf("Cancelling download\n");
				still_download = false;
				break;
			}
			if (FPAD_OK(0)) {
				gprintf("okay\n");
				break;
			}
			GRRLIB_Render();
		}
		if(!still_download) {
			*current_line = line;
			return false;
		}
	}
	*current_line = line;
	return (*major + *minor) > 0;

}
Exemple #3
0
void Display()
{
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_POINTS);
		DrawBuffer();
	glEnd();
	glutSwapBuffers();
}
Exemple #4
0
void DoBuffer(struct Buffer *b, int x, int y, int dx, int w, int xn,
	      int yn)
{
	SetBuffer(x + xn, y + yn, b, w);
	if (fLOS) {
		LineOfSight(x, y, b, IS_SHADOW);
		FixBuffer(b, IS_SHADOW);
	}
	DrawBuffer(b, dx);
}
Exemple #5
0
void StartDemo(void) {
	int x, y, line;
	int tx1 = 0, ty1 = 0, tx2 = 0, ty2 = 0, tx3 = 0, ty3 = 0;
	int px1, py1, px2, py2, px3, py3;
	
	SetPause(16);	// fps ~= 60
	
	CreateSinT();
	
	//					AARRGGBB
	imgClear(Disp, 0xFF000000);		// очищаем экран
	
	while(1) {
		py1 = ty1;
		py2 = ty2;
		py3 = ty3;
	
		for (y = 0; y != Disp.height; y++) {
			line = y * Disp.width;
			px1 = tx1;
			px2 = tx2;
			px3 = tx3;
			
			for (x = 0; x != Disp.width; x++) {
				px1 = px1 + 1;
				px2 = px2 + 1;
				px3 = px3 + 1;
			
				Disp.pBitMap[((x + line) << 2) + 2] = (SinT[px1 & 255] + SinT[py1 & 255]) >> 1;	// R
				Disp.pBitMap[((x + line) << 2) + 1] = (SinT[px2 & 255] + SinT[py2 & 255]) >> 1;	// G
				Disp.pBitMap[((x + line) << 2) + 0] = (SinT[px3 & 255] + SinT[(py3 + 63) & 255]) >> 1;	// B
			}
			py1 = py1 + 1;
			py2 = py2 + 1;
			py3 = py3 + 1;
		}
		tx1 = tx1 + 1;
		ty1 = ty1 + 1;
		tx2 = tx2 + 2;
		ty2 = ty2 + 2;
		tx3 = ty3 + 3;
		ty3 = ty3 + 3;
		
		DrawBuffer(Disp);				// копируем в окно
		Pause();
	}
}
int show_images(Fg_Struct *fg, int *nr, int num_imgs, int w, int h)
{
#if SHOW_DISP
	int i;
	int disp;
	unsigned long *img;

	disp = CreateDisplay(8, w, h);
	SetBufferWidth(disp, w, h);
	for(i = 0; i < num_imgs; i++) {
		if(nr[i] > FG_OK) {
			img = Fg_getImagePtr(fg, nr[i], PORT_A);
			DrawBuffer(disp, img, nr[i], "SimpleTiming");
			Sleep(PAUSE);
		}
	}
	CloseDisplay(disp);
#endif
	return FG_OK;
}
void Render(void)
{
    glViewport(0, 0, winWidth, winHeight);
    
    if(hasError) {
        // If an OpenGL error has been encountered the screen will render solid green
        // Check the console output for error details
        glClearColor(0.0f, 1.0f, 0.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else if(invalidFramebuffer) {
        // If the framebuffer is invalid but no OpenGL errors are indicated, the screen will render solid red
        glClearColor(1.0f, 0.0f, 0.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else if(maxSizeReached) {
        // Render blue if we've successfully allocated a buffer of the maximum reported size without error
        glClearColor(0.0f, 0.0f, 1.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else {
        // Steadily grow the multisample buffer size.
        // This is expected to fail at some point, since we should eventually hit memory or other limits.
        buffer->Resize(buffer->width * 1.2, buffer->height * 1.2);
        
        if(!hasError) {
            // Check the framebuffer to ensure it's valid and can be drawn to
            if(!buffer->Test()) {
                printf("Framebuffer appears to be invalid but no GL errors have been indicated. Should not get here!\n");
                invalidFramebuffer = true;
            }
            
            // Draws a quad into the center of the multisample buffer
            DrawQuad(buffer);
            
            // Draws the contents of the multisample buffer to the screen
            DrawBuffer(buffer);
        }
    }
    
    glutSwapBuffers();
    glutPostRedisplay();
}
Exemple #8
0
//Render Manager.
void CConsole::Render()
{
	if (! (m_bVisible || m_bToggle) ) return;

	PROFILE3_GPU("console");

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	CShaderTechniquePtr solidTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
	solidTech->BeginPass();
	CShaderProgramPtr solidShader = solidTech->GetShader();

	CMatrix3D transform = GetDefaultGuiMatrix();

	// animation: slide in from top of screen
	const float DeltaY = (1.0f - m_fVisibleFrac) * m_fHeight;
	transform.PostTranslate(m_fX, m_fY - DeltaY, 0.0f); // move to window position
	solidShader->Uniform(str_transform, transform);

	DrawWindow(solidShader);

	solidTech->EndPass();

	CShaderTechniquePtr textTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
	textTech->BeginPass();
	CTextRenderer textRenderer(textTech->GetShader());
	textRenderer.Font(CStrIntern(CONSOLE_FONT));
	textRenderer.SetTransform(transform);

	DrawHistory(textRenderer);
	DrawBuffer(textRenderer);

	textRenderer.Render();

	textTech->EndPass();

	glDisable(GL_BLEND);
}
Exemple #9
0
int main(void)
{

	// Nastavíme pozici ètvercù 
	//int pos_x = 10;
	//int pos_y = 10;
	//int pos_x2 = 100;
	//int pos_y2 = 100;
	//------------------------

	// Nastavíme barvu ètvercù r,g,b
	//int r = 0;
	//int g = 255;
	//int b = 0;
	//-------------------------

	allegro_init();	 // inicializace allegra
	install_keyboard(); // inicializace klavesnice
	obr = load_bitmap("obr.bmp",NULL);
	//obr2 = load_bitmap("obr2.bmp",NULL);

	set_color_depth(8); // Nastavíme hloubku , Grafický mod ,a výšku a šíøku obrazovky
	if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W ,SCR_H, 0, 0)) 
	{
		set_color_depth(24);
		if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H, 0, 0)) 
		{
			set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H , 0, 0)) 
			{
				set_color_depth(15);
				if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H, 0, 0)) 
				{
					allegro_message("Video Error: %s.\n", allegro_error);
					return 1;
				}
			}
		}
	}
	InitDoubleBuffering();
	Init();              

	while (!key[KEY_ESC])
	{

       /* if(key[KEY_UP])
		{ pos_y -= 1;}
		if(key[KEY_DOWN])
		{ pos_y += 1;}
		if(key[KEY_RIGHT])
		{ pos_x += 1;}
		if(key[KEY_LEFT])
		{ pos_x -= 1;}

		if(key[KEY_W])
		{ pos_y2 -= 1;}
		if(key[KEY_S])
		{ pos_y2 += 1;}
		if(key[KEY_D])
		{ pos_x2 += 1;}
		if(key[KEY_A])
		{ pos_x2 -= 1;}

		if((pos_x > pos_x2 - 20) && ( pos_x < pos_x2 + 20) && (pos_y > pos_y2 - 20 ) && (pos_y < pos_y2 + 20)){}
		else{}
		*/
		
		Posun();
		DrawEnemy();
//		Draw();
		DrawBuffer();
		Colision();
		clear_bitmap(buffer);
		rest(10); //jinak tez wait()

	}
	destroy_bitmap(obr);
	return 0;
}
Exemple #10
0
void DrawScreen(struct Buffer *b, TActor * player1, TActor * player2)
{
	static int x = 0;
	static int y = 0;
	int xNoise, yNoise;

	if (screenShaking) {
		xNoise = rand() & 7;
		yNoise = rand() & 7;
	} else
		xNoise = yNoise = 0;

	if (player1 && player2) {
		if (abs(player1->tileItem.x - player2->tileItem.x) < gOptions.xSplit
		    && abs(player1->tileItem.y - player2->tileItem.y) < gOptions.ySplit) {
			SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
			// One screen
			x = (player1->tileItem.x +
			     player2->tileItem.x) / 2;
			y = (player1->tileItem.y +
			     player2->tileItem.y) / 2;

			SetBuffer(x + xNoise, y + yNoise, b, X_TILES);
			if (fLOS) {
				LineOfSight(player1->tileItem.x,
					    player1->tileItem.y, b,
					    IS_SHADOW);
				LineOfSight(player2->tileItem.x,
					    player2->tileItem.y, b,
					    IS_SHADOW2);
				FixBuffer(b, IS_SHADOW | IS_SHADOW2);
			}
			DrawBuffer(b, 0);
		} else {
			SetClip(0, 0, (SCREEN_WIDTH / 2) - 1, SCREEN_HEIGHT - 1);
			DoBuffer(b, player1->tileItem.x, player1->tileItem.y, 0, X_TILES_HALF, xNoise, yNoise);
			SetLeftEar(player1->tileItem.x, player1->tileItem.y);
			SetClip((SCREEN_WIDTH / 2) + 1, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
			DoBuffer(b, player2->tileItem.x, player2->tileItem.y, (SCREEN_WIDTH / 2) + 1, X_TILES_HALF, xNoise, yNoise);
			SetRightEar(player2->tileItem.x, player2->tileItem.y);
			x = player1->tileItem.x;
			y = player1->tileItem.y;
			BlackLine();
		}
	} else if (player1) {
		SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
		DoBuffer(b, player1->tileItem.x, player1->tileItem.y, 0,
			 X_TILES, xNoise, yNoise);
		SetLeftEar(player1->tileItem.x, player1->tileItem.y);
		SetRightEar(player1->tileItem.x, player1->tileItem.y);
		x = player1->tileItem.x;
		y = player1->tileItem.y;
	} else if (player2) {
		SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
		DoBuffer(b, player2->tileItem.x, player2->tileItem.y, 0,
			 X_TILES, xNoise, yNoise);
		SetLeftEar(player2->tileItem.x, player2->tileItem.y);
		SetRightEar(player2->tileItem.x, player2->tileItem.y);
		x = player2->tileItem.x;
		y = player2->tileItem.y;
	} else
		DoBuffer(b, x, y, 0, X_TILES, xNoise, yNoise);
	SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
}
Exemple #11
0
/**
 * \brief Initialize a (new or reused) OpenGL context.
 * set global gl-related variables to their default values
 */
static int initGl(uint32_t d_width, uint32_t d_height) {
  int scale_type = mipmap_gen ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
  autodetectGlExtensions();
  gl_target = use_rectangle == 1 ? GL_TEXTURE_RECTANGLE : GL_TEXTURE_2D;
  yuvconvtype = use_yuv | lscale << YUV_LUM_SCALER_SHIFT | cscale << YUV_CHROM_SCALER_SHIFT;

  texSize(image_width, image_height, &texture_width, &texture_height);

  Disable(GL_BLEND);
  Disable(GL_DEPTH_TEST);
  DepthMask(GL_FALSE);
  Disable(GL_CULL_FACE);
  Enable(gl_target);
  DrawBuffer(vo_doublebuffering?GL_BACK:GL_FRONT);
  TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n",
          texture_width, texture_height);

  if (is_yuv) {
    int i;
    int xs, ys;
    mp_get_chroma_shift(image_format, &xs, &ys);
    GenTextures(21, default_texs);
    default_texs[21] = 0;
    for (i = 0; i < 7; i++) {
      ActiveTexture(GL_TEXTURE1 + i);
      BindTexture(GL_TEXTURE_2D, default_texs[i]);
      BindTexture(GL_TEXTURE_RECTANGLE, default_texs[i + 7]);
      BindTexture(GL_TEXTURE_3D, default_texs[i + 14]);
    }
    ActiveTexture(GL_TEXTURE1);
    glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type,
                     texture_width >> xs, texture_height >> ys, 128);
    if (mipmap_gen)
      TexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE);
    ActiveTexture(GL_TEXTURE2);
    glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type,
                     texture_width >> xs, texture_height >> ys, 128);
    if (mipmap_gen)
      TexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE);
    ActiveTexture(GL_TEXTURE0);
    BindTexture(gl_target, 0);
  }
  if (is_yuv || custom_prog)
  {
    if ((MASK_NOT_COMBINERS & (1 << use_yuv)) || custom_prog) {
      if (!GenPrograms || !BindProgram) {
        mp_msg(MSGT_VO, MSGL_ERR, "[gl] fragment program functions missing!\n");
      } else {
        GenPrograms(1, &fragprog);
        BindProgram(GL_FRAGMENT_PROGRAM, fragprog);
      }
    }
    update_yuvconv();
  }
  glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type,
                   texture_width, texture_height, 0);
  if (mipmap_gen)
    TexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE);

  resize(d_width, d_height);

  ClearColor( 0.0f,0.0f,0.0f,0.0f );
  Clear( GL_COLOR_BUFFER_BIT );
  if (SwapInterval && swap_interval >= 0)
    SwapInterval(swap_interval);
  return 1;
}
Exemple #12
0
bool RT::Scene::Render(SDLApplication *const app, const RT::Scene::SharedCallback &callback, \
		const size_t Step, const bool rectangles, const size_t extra)
{
	const size_t n = static_cast<size_t>(app->Screen->h * app->Screen->w);
	const size_t qh = (static_cast<size_t>(static_cast<unsigned int>(app->Screen->h)) + Step - 1) / Step;
	const size_t qw = (static_cast<size_t>(static_cast<unsigned int>(app->Screen->w)) + Step - 1) / Step;
	const size_t qn = qh * qw;

	// резервируем памяти для максимального качества
	buffer.reserve(n);

	// реально используем для текущего
	buffer.clear();
	buffer.resize(qn, Palette::Black);

	if(camera)
	{
		const size_t updateInterval = std::max<size_t>(qn / 100, 100);

		ColorContainer::iterator buffer_iterator = buffer.begin();

		for(size_t yt = 0, i = 0; yt < static_cast<size_t>(app->Screen->h); yt += Step)
		{
			for(size_t xl = 0; xl < static_cast<size_t>(app->Screen->w); xl += Step, ++i)
			{
				RealColor SummaryColor(Palette::Black);

				// разбиваем окрестность пикселя (x, y)..(x + 1, y + 1) на extra строк и столбцов
				// для каждой ячейки проводим луч и затем берём среднее
				for(size_t ex = 0; ex < extra; ++ex)
					for(size_t ey = 0; ey < extra; ++ey)
					{
						// находим центры каждой ячейки
						const double x = \
								static_cast<double>(xl) + \
								(static_cast<double>(ex) + 0.5) \
								/ static_cast<double>(extra) \
								* static_cast<double>(Step);

						const double y = \
								static_cast<double>(yt) + \
								(static_cast<double>(ey) + 0.5) \
								/ static_cast<double>(extra) \
								* static_cast<double>(Step);

						const RT::Ray ray = camera->GenerateRay(x, y);

						SummaryColor += Trace(ray);
					}

				*buffer_iterator = SummaryColor / double(extra * extra);

				++buffer_iterator;

				if(i % updateInterval == 0)
				{
					const size_t percent = 90 *
						static_cast<size_t>(buffer_iterator - buffer.begin()) / qn;

					if(callback->call(static_cast<double>(percent)))
					{
						return false;
					}
				}
			}
		}
		assert(buffer_iterator == buffer.end());


		// тут можно делать tonemapping
		// найти максимум
		double mx = 0;
		for(ColorContainer::const_iterator it = buffer.begin(); it != buffer.end(); ++it)
		{
			mx = std::max(mx, std::max(it->R, std::max(it->G, it->B)));
		}

		// нормирую цвет
		if(mx != 0)
		{
			const double n = 255.0 / mx;
			for(ColorContainer::iterator it = buffer.begin(); it != buffer.end(); ++it)
			{
				*it = *it * n;
			}
		}
	}


	if(callback->call(95))
		return false;

	// остался последний шаг, перенести всё это на экран

	DrawBuffer(app, rectangles, Step);

	callback->call(100);

	return true;
}