Пример #1
0
void raster_rgba_vline_fade(pb_rgba *pb, int y1, uint32_t color1, int y2, uint32_t color2, int x)
{
	int ydiff = y2 - y1;
	if (ydiff == 0)
		return;

	int c1rd = GET_R(color1);
	int c1gr = GET_G(color1);
	int c1bl = GET_B(color1);

	int c2rd = GET_R(color2);
	int c2gr = GET_G(color2);
	int c2bl = GET_B(color2);

	int rdx = c2rd - c1rd;
	int gdx = c2gr - c1gr;
	int bdx = c2bl - c1bl;

	float factor = 0.0f;
	float factorStep = 1.0f / (float)ydiff;

	// draw each pixel in the span
	for (int y = y1; y < y2; y++) {
		int rd = c1rd + (int)(rdx*factor);
		int gr = c1gr + (int)(gdx*factor);
		int bl = c1bl + (int)(bdx*factor);
		int fg = RGBA(rd, gr, bl, 255);
		pb_rgba_set_pixel(pb, x, y, fg);

		factor += factorStep;
	}
}
Пример #2
0
void raster_rgba_blend_alphamap(pb_rgba *pb, const int x, const int y, const unsigned char *bitmap, const int w, const int h, const uint32_t color)
{
	int xpos = x;
	int ypos = y;

	uint32_t *dstPtr = (uint32_t *)pb->data;
	uint8_t *srcPtr = (uint8_t *)bitmap;

	dstPtr += y*pb->pixelpitch + x;
	uint32_t *dstRowPtr = dstPtr;

	int srcrow = 0;
	for (srcrow = 0; srcrow < h; srcrow++)
	{
		xpos = x;

		for (int srccol = 0; srccol < w; srccol++)
		{
			if (*srcPtr > 0)
			{
				int dstColor = RGBA(GET_R(color), GET_G(color), GET_B(color), *srcPtr);
				pb_rgba_cover_pixel(pb, xpos, ypos, dstColor);
			}
			xpos++;
			srcPtr += 1;
		}

		ypos++;
	}
}
Пример #3
0
int set_pixel_rgb(struct pixmap *p, int x, int y, unsigned char r, unsigned char g, unsigned char b)
{
	int	 result = 0;

	if (p) {
		if (x >= 0 && x < p->width) {
			if (y >= 0 && y < p->height) {
				if (p->components == 1) {
					GET_R(p, x, y) = RED * r + GREEN * g + BLUE * b;
				} else {
					GET_R(p, x, y) = r;
					GET_G(p, x, y) = g;
					GET_B(p, x, y) = b;
				}
			} else {
				if (!quiet) fprintf(stderr, "%s: set_pixel_rgb: error: y out of range\n", __progname);
				result = -1;
			}
		} else {
			if (!quiet) fprintf(stderr, "%s: set_pixel_rgb: error: x out of range\n", __progname);
			result = -1;
		}
	}

	return result;
}
Пример #4
0
void CGUITextureGL::Begin(UTILS::Color color)
{
  CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
  texture->LoadToGPU();
  if (m_diffuse.size())
    m_diffuse.m_textures[0]->LoadToGPU();

  texture->BindToUnit(0);

  // Setup Colors
  m_col[0] = (GLubyte)GET_R(color);
  m_col[1] = (GLubyte)GET_G(color);
  m_col[2] = (GLubyte)GET_B(color);
  m_col[3] = (GLubyte)GET_A(color);

  bool hasAlpha = m_texture.m_textures[m_currentFrame]->HasAlpha() || m_col[3] < 255;

  if (m_diffuse.size())
  {
    if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255 )
    {
      m_renderSystem->EnableShader(SM_MULTI);
    }
    else
    {
      m_renderSystem->EnableShader(SM_MULTI_BLENDCOLOR);
    }

    hasAlpha |= m_diffuse.m_textures[0]->HasAlpha();

    m_diffuse.m_textures[0]->BindToUnit(1);
  }
  else
  {
    if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255)
    {
      m_renderSystem->EnableShader(SM_TEXTURE_NOBLEND);
    }
    else
    {
      m_renderSystem->EnableShader(SM_TEXTURE);
    }
  }

  if (hasAlpha)
  {
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE);
    glEnable(GL_BLEND);
  }
  else
  {
    glDisable(GL_BLEND);
  }
  m_packedVertices.clear();
  m_idx.clear();
}
Пример #5
0
void test_bitmap_color_transform_macro_c(short* buffer) {
  short* p = buffer;
  int n;
  for (n = 0; n < IMAGE_HEIGHT * IMAGE_WIDTH; ++n, ++p) {
      int r = GET_R(*p);
      int g = GET_G(*p);
      int b = GET_B(*p);
      *p = (short)TO_RGB(g, b, r);
  }
}
Пример #6
0
void pb_rgba_cover_pixel(pb_rgba *pb, const unsigned int x, const unsigned int y, const uint32_t value)
{

	// Quick reject if the foreground pixel has both 0 opacity
	// and 0 for color component values
	if (0 == value) {
		return;
	}

	if (0 == GET_A(value)) {
		// Combine the colors, but don't
		// change the alpha of the background
	} else if (255 == GET_A(value)) {
		// The foreground opacity is full, so set
		// the color
		// and set the background alpha to full as well
		pb_rgba_set_pixel(pb, x, y, value);
	} else {
		// All other cases where doing a cover of something
		// other than full opacity
		uint8_t alpha = GET_A(value);
		int32_t dstPixel = pb_rgba_get_pixel(pb, x, y);


		int dstColor = RGBA(
			lerp255(GET_R(dstPixel), GET_R(value), alpha),
			lerp255(GET_G(dstPixel), GET_G(value), alpha), 
			lerp255(GET_B(dstPixel), GET_B(value), alpha), 
			lerp255(GET_A(dstPixel), GET_A(value), alpha)
		);
		pb_rgba_set_pixel(pb, x, y, dstColor);
		/*
		pix_rgba * B = (pix_rgba *)&pb->data[(y*(pb)->pixelpitch) + x];
		B->r = lerp255(B->r, GET_R(value), alpha);
		B->g = lerp255(B->g, GET_R(value), alpha);
		B->b = lerp255(B->b, GET_R(value), alpha);
		B->a = lerp255(B->a, GET_R(value), alpha);
		*/
	}
}
Пример #7
0
void CGUITextureGL::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
  if (texture)
  {
    glActiveTextureARB(GL_TEXTURE0_ARB);
    texture->LoadToGPU();
    glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());
    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
  }
  else
  glDisable(GL_TEXTURE_2D);

  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);          // Turn Blending On
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  // diffuse coloring
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
  glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
  VerifyGLState();

  glBegin(GL_QUADS);

  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));

  CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
  glTexCoord2f(coords.x1, coords.y1);
  glVertex3f(rect.x1, rect.y1, 0);
  glTexCoord2f(coords.x2, coords.y1);
  glVertex3f(rect.x2, rect.y1, 0);
  glTexCoord2f(coords.x2, coords.y2);
  glVertex3f(rect.x2, rect.y2, 0);
  glTexCoord2f(coords.x1, coords.y2);
  glVertex3f(rect.x1, rect.y2, 0);

  glEnd();
  if (texture)
    glDisable(GL_TEXTURE_2D);
}
Пример #8
0
bool CRenderSystemGLES::ClearBuffers(color_t color)
{
  if (!m_bRenderCreated)
    return false;

  float r = GET_R(color) / 255.0f;
  float g = GET_G(color) / 255.0f;
  float b = GET_B(color) / 255.0f;
  float a = GET_A(color) / 255.0f;

  glClearColor(r, g, b, a);

  GLbitfield flags = GL_COLOR_BUFFER_BIT;
  glClear(flags);

  return true;
}
Пример #9
0
void CGUITextureGL::Begin(color_t color)
{
  m_col[0] = (GLubyte)GET_R(color);
  m_col[1] = (GLubyte)GET_G(color);
  m_col[2] = (GLubyte)GET_B(color);
  m_col[3] = (GLubyte)GET_A(color);

  CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
  glActiveTextureARB(GL_TEXTURE0_ARB);
  texture->LoadToGPU();
  if (m_diffuse.size())
    m_diffuse.m_textures[0]->LoadToGPU();

  glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());
  glEnable(GL_TEXTURE_2D);

  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);          // Turn Blending On
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  // diffuse coloring
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
  glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
  VerifyGLState();

  if (m_diffuse.size())
  {
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glBindTexture(GL_TEXTURE_2D, m_diffuse.m_textures[0]->GetTextureObject());
    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
    VerifyGLState();
  }
  //glDisable(GL_TEXTURE_2D); // uncomment these 2 lines to switch to wireframe rendering
  //glBegin(GL_LINE_LOOP);
  glBegin(GL_QUADS);
}
Пример #10
0
bool CRenderSystemGL::ClearBuffers(color_t color)
{
  if (!m_bRenderCreated)
    return false;

  /* clear is not affected by stipple pattern, so we can only clear on first frame */
  if(m_stereoMode == RENDER_STEREO_MODE_INTERLACED && m_stereoView == RENDER_STEREO_VIEW_RIGHT)
    return true;

  float r = GET_R(color) / 255.0f;
  float g = GET_G(color) / 255.0f;
  float b = GET_B(color) / 255.0f;
  float a = GET_A(color) / 255.0f;

  glClearColor(r, g, b, a);

  GLbitfield flags = GL_COLOR_BUFFER_BIT;
  glClear(flags);

  return true;
}
Пример #11
0
void CGUITextureGL::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
  if (texture)
  {
    texture->LoadToGPU();
    texture->BindToUnit(0);
  }

  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);          // Turn Blending On

  VerifyGLState();

  GLubyte col[4];
  GLubyte idx[4] = {0, 1, 3, 2};  //determines order of the vertices
  GLuint vertexVBO;
  GLuint indexVBO;

  struct PackedVertex
  {
    float x, y, z;
    float u1, v1;
  }vertex[4];

  if (texture)
    g_Windowing.EnableShader(SM_TEXTURE);
  else
    g_Windowing.EnableShader(SM_DEFAULT);

  GLint posLoc = g_Windowing.ShaderGetPos();
  GLint tex0Loc = g_Windowing.ShaderGetCoord0();
  GLint uniColLoc = g_Windowing.ShaderGetUniCol();

  // Setup Colors
  col[0] = (GLubyte)GET_R(color);
  col[1] = (GLubyte)GET_G(color);
  col[2] = (GLubyte)GET_B(color);
  col[3] = (GLubyte)GET_A(color);

  glUniform4f(uniColLoc, col[0] / 255.0f, col[1] / 255.0f, col[2] / 255.0f, col[3] / 255.0f);

  // bottom left
  vertex[0].x = rect.x1;
  vertex[0].y = rect.y1;
  vertex[0].z = 0;

  // bottom right
  vertex[1].x = rect.x2;
  vertex[1].y = rect.y1;
  vertex[1].z = 0;

  // top right
  vertex[2].x = rect.x2;
  vertex[2].y = rect.y2;
  vertex[2].z = 0;

  // top left
  vertex[3].x = rect.x1;
  vertex[3].y = rect.y2;
  vertex[3].z = 0;

  if (texture)
  {
    CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
    vertex[0].u1 = vertex[3].u1 = coords.x1;
    vertex[0].v1 = vertex[1].v1 = coords.y1;
    vertex[1].u1 = vertex[2].u1 = coords.x2;
    vertex[2].v1 = vertex[3].v1 = coords.y2;
  }

  glGenBuffers(1, &vertexVBO);
  glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex)*4, &vertex[0], GL_STATIC_DRAW);

  glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, x)));
  glEnableVertexAttribArray(posLoc);

  if (texture)
  {
    glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u1)));
    glEnableVertexAttribArray(tex0Loc);
  }

  glGenBuffers(1, &indexVBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*4, idx, GL_STATIC_DRAW);
  
  glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, 0);

  glDisableVertexAttribArray(posLoc);
  if (texture)
    glDisableVertexAttribArray(tex0Loc);

  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glDeleteBuffers(1, &vertexVBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  glDeleteBuffers(1, &indexVBO);

  g_Windowing.DisableShader();
}
Пример #12
0
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
  CRenderSystemGLES *renderSystem = dynamic_cast<CRenderSystemGLES*>(&CServiceBroker::GetRenderSystem());
  if (texture)
  {
    texture->LoadToGPU();
    texture->BindToUnit(0);
  }

  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);          // Turn Blending On

  VerifyGLState();

  GLubyte col[4];
  GLfloat ver[4][3];
  GLfloat tex[4][2];
  GLubyte idx[4] = {0, 1, 3, 2};        //determines order of triangle strip

  if (texture)
    renderSystem->EnableGUIShader(SM_TEXTURE);
  else
    renderSystem->EnableGUIShader(SM_DEFAULT);

  GLint posLoc   = renderSystem->GUIShaderGetPos();
  GLint tex0Loc  = renderSystem->GUIShaderGetCoord0();
  GLint uniColLoc= renderSystem->GUIShaderGetUniCol();

  glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, 0, ver);
  if (texture)
    glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);

  glEnableVertexAttribArray(posLoc);
  if (texture)
    glEnableVertexAttribArray(tex0Loc);

  // Setup Colors
  col[0] = (GLubyte)GET_R(color);
  col[1] = (GLubyte)GET_G(color);
  col[2] = (GLubyte)GET_B(color);
  col[3] = (GLubyte)GET_A(color);

  glUniform4f(uniColLoc, col[0] / 255.0f, col[1] / 255.0f, col[2] / 255.0f, col[3] / 255.0f);

  ver[0][0] = ver[3][0] = rect.x1;
  ver[0][1] = ver[1][1] = rect.y1;
  ver[1][0] = ver[2][0] = rect.x2;
  ver[2][1] = ver[3][1] = rect.y2;
  ver[0][2] = ver[1][2] = ver[2][2] = ver[3][2]= 0;

  if (texture)
  {
    // Setup texture coordinates
    CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
    tex[0][0] = tex[3][0] = coords.x1;
    tex[0][1] = tex[1][1] = coords.y1;
    tex[1][0] = tex[2][0] = coords.x2;
    tex[2][1] = tex[3][1] = coords.y2;
  }
  glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

  glDisableVertexAttribArray(posLoc);
  if (texture)
    glDisableVertexAttribArray(tex0Loc);

  renderSystem->DisableGUIShader();
}
void CEmTubeSplashViewContainer::Draw(const TRect& /*aRect*/) const
	{

    CWindowGc& gc = SystemGc();

    gc.SetClippingRect( Rect() );

	gc.SetBrushColor( KRgbWhite );
    gc.Clear( Rect() );

	TRect rect = Rect();
	TInt x, y;

	x = (rect.Width() / 2) - (KBitmapSize / 2);
	y = (rect.Height() / 2) - (KBitmapSize / 2);

	TInt s_width = iBitmap->ScanLineLength(iBitmap->SizeInPixels().iWidth, EColor16MU ) / 4;
	TInt s_height = iBitmap->SizeInPixels().iHeight;

	TInt d_width = iTmpBitmap->ScanLineLength(iTmpBitmap->SizeInPixels().iWidth, EColor16MU ) / 4;
//	TInt d_height = iTmpBitmap->SizeInPixels().iHeight;

	iBitmap->LockHeap(ETrue);
	iTmpBitmap->LockHeap(ETrue);

	TUint32* src = (TUint32*) iBitmap->DataAddress();
	TUint32* dst = (TUint32*) iTmpBitmap->DataAddress();

#define GET_R( rgb ) ((rgb >> 16) & 0xff)
#define GET_G( rgb ) ((rgb >> 8) & 0xff)
#define GET_B( rgb ) (rgb & 0xff)

#define SET_R( r ) ((r & 0xff) << 16 )
#define SET_G( g ) ((g & 0xff) << 8 )
#define SET_B( b ) ( b & 0xff)

	TUint32 alpha = iAlpha * 255;
	TUint32 alpha1 = (KAlphaMax - iAlpha);
	for (TInt i = 0; i < s_height; i++)
    	{
    	TUint32* d = dst;
    	TUint32* s = src;
        for (TInt j = 0; j < s_width; j++)
	        {
			TUint32 rgb = *s++;

			TUint32 r = ((GET_R( rgb ) * alpha1) + alpha) >> 8;
			TUint32 g = ((GET_G( rgb ) * alpha1) + alpha) >> 8;
			TUint32 b = ((GET_B( rgb ) * alpha1) + alpha) >> 8;

			rgb = SET_R( r ) + SET_G( g ) + SET_B( b );
			*d++ = rgb;
	        }
        dst += d_width;
        src += s_width;
		}

	iBitmap->UnlockHeap(ETrue);
	iTmpBitmap->UnlockHeap(ETrue);

	gc.BitBlt( TPoint( x, y ), iTmpBitmap);
    gc.CancelClippingRect();
	}
Пример #14
0
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t color)
{
#ifdef HAS_DX
  static const DWORD FVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;

  Vertex vertex[5];
  for (int i = 0; i < 4; i++)
  {
    vertex[i].pos = XMFLOAT3( x[i], y[i], 0);
    CD3DHelper::XMStoreColor(&vertex[i].color, color);
    vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f);
    vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f);
  }

  if (pTexture)
  {
    vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth();
    vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight();
  }
  else
  {
    vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f;
    vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f;
  }
  vertex[4] = vertex[0]; // Not used when pTexture != NULL

  CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader();
  pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND);

  // Set state to render the image
  if (pTexture)
  {
    pTexture->LoadToGPU();
    CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture);
    ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource();
    pGUIShader->SetShaderViews(1, &shaderRes);
    pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]);
  }
  else
  {
    if (!UpdateVertexBuffer(vertex))
      return;

    ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();

    unsigned stride = sizeof(Vertex);
    unsigned offset = 0;
    pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset);
    pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP);

    pGUIShader->Draw(5, 0);
    pGUIShader->RestoreBuffers();
  }

#elif defined(HAS_GL)
  if (pTexture)
  {
    int unit = 0;
    pTexture->LoadToGPU();
    pTexture->BindToUnit(unit++);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);          // Turn Blending On

    // diffuse coloring
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

    if(g_Windowing.UseLimitedColor())
    {
      // compress range
      pTexture->BindToUnit(unit++); // dummy bind
      const GLfloat rgba1[4] = {(235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, 1.0f};
      glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
      glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba1);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_MODULATE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);

      // transition
      pTexture->BindToUnit(unit++); // dummy bind
      const GLfloat rgba2[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f};
      glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
      glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba2);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);
    }
  }
  else
    glDisable(GL_TEXTURE_2D);
  glPolygonMode(GL_FRONT_AND_BACK, pTexture ? GL_FILL : GL_LINE);

  glBegin(GL_QUADS);
  float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
  if (pTexture)
  {
    u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
    v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
  }

  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u1, v1);
  glVertex3f(x[0], y[0], 0);

  // Bottom-left vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u2, v1);
  glVertex3f(x[1], y[1], 0);

  // Bottom-right vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u2, v2);
  glVertex3f(x[2], y[2], 0);

  // Top-right vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u1, v2);
  glVertex3f(x[3], y[3], 0);

  glEnd();
#elif defined(HAS_GLES)
  if (pTexture)
  {
    pTexture->LoadToGPU();
    pTexture->BindToUnit(0);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);          // Turn Blending On

    g_Windowing.EnableGUIShader(SM_TEXTURE);
  }
  else
  {
    glDisable(GL_TEXTURE_2D);

    g_Windowing.EnableGUIShader(SM_DEFAULT);
  }

  float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
  if (pTexture)
  {
    u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
    v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
  }

  GLubyte col[4];
  GLfloat ver[4][3];
  GLfloat tex[4][2];
  GLubyte idx[4] = {0, 1, 3, 2};        //determines order of triangle strip

  GLint posLoc  = g_Windowing.GUIShaderGetPos();
  GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
  GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

  glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, 0, ver);
  glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);

  glEnableVertexAttribArray(posLoc);
  glEnableVertexAttribArray(tex0Loc);

  // Setup Colour values
  col[0] = (GLubyte)GET_R(color);
  col[1] = (GLubyte)GET_G(color);
  col[2] = (GLubyte)GET_B(color);
  col[3] = (GLubyte)GET_A(color);

  for (int i=0; i<4; i++)
  {
    // Setup vertex position values
    ver[i][0] = x[i];
    ver[i][1] = y[i];
    ver[i][2] = 0.0f;
  }
  // Setup texture coordinates
  tex[0][0] = tex[3][0] = u1;
  tex[0][1] = tex[1][1] = v1;
  tex[1][0] = tex[2][0] = u2;
  tex[2][1] = tex[3][1] = v2;

  glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f));
  glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

  glDisableVertexAttribArray(posLoc);
  glDisableVertexAttribArray(tex0Loc);

  g_Windowing.DisableGUIShader();
#else
// SDL render
  g_Windowing.BlitToScreen(m_pImage, NULL, NULL);
#endif
}
Пример #15
0
int32_t GLOBALDATA::get_avg_bgcolor(int32_t x1, int32_t y1,
                                    int32_t x2, int32_t y2,
                                    double xv, double yv)
{
	// Movement
	int32_t mvx      = ROUND(10. * xv); // eliminate slow movement
	int32_t mvy      = ROUND(10. * yv); // eliminate slow movement
	bool    mv_left  = mvx < 0;
	bool    mv_right = mvx > 0;
	bool    mv_up    = mvy < 0;
	bool    mv_down  = mvy > 0;

	// Boundaries
	int32_t min_x = 1;
	int32_t max_x = env.screenWidth - 2;
	int32_t min_y = env.isBoxed ? MENUHEIGHT + 1 : MENUHEIGHT;
	int32_t max_y = env.screenHeight - 2;

	// Coordinates
	int32_t left   = std::max(std::min(x1, x2), min_x);
	int32_t right  = std::min(std::max(x1, x2), max_x);
	int32_t centre = (x1 + x2) / 2;
	int32_t top    = std::max(std::min(y1, y2), min_y);
	int32_t bottom = std::min(std::max(y1, y2), max_y);
	int32_t middle = (y1 + y2) / 2;


	// Colors:
	int32_t col_tl, col_tc, col_tr; // top row
	int32_t col_ml, col_mc, col_mr; // middle row
	int32_t col_bl, col_bc, col_br; // bottom row
	int32_t r = 0, g = 0, b = 0;


	// Get Sky or Terrain colour, whatever fits:
	/*---------------------
	  --- Left side ---
	  ---------------------*/
	if ( PINK == (col_tl = getpixel(terrain, left, top)) )
		col_tl = getpixel(env.sky, left, top);
	if ( PINK == (col_ml = getpixel(terrain, left, middle)) )
		col_ml = getpixel(env.sky, left, middle);
	if ( PINK == (col_bl = getpixel(terrain, left, bottom)) )
		col_bl = getpixel(env.sky, left, bottom);

	/*---------------------
	  --- The Center ---
	---------------------*/
	if ( PINK == (col_tc = getpixel(terrain, centre, top)) )
		col_tc = getpixel(env.sky, centre, top);
	if ( PINK == (col_mc = getpixel(terrain, centre, middle)) )
		col_mc = getpixel(env.sky, centre, middle);
	if ( PINK == (col_bc = getpixel(terrain, centre, bottom)) )
		col_bc = getpixel(env.sky, centre, bottom);

	/*----------------------
	  --- Right side ---
	----------------------*/
	if ( PINK == (col_tr = getpixel(terrain, right, top)) )
		col_tr = getpixel(env.sky, right, top);
	if ( PINK == (col_mr = getpixel(terrain, right, middle)) )
		col_mr = getpixel(env.sky, right, middle);
	if ( PINK == (col_br = getpixel(terrain, right, bottom)) )
		col_br = getpixel(env.sky, right, bottom);


	// Fetch the rgb parts, according to movement:

	/* --- X-Movement --- */
	if (mv_left) {
		// Movement to the left, weight left side colour twice
		r += (GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl)) * 2;
		g += (GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl)) * 2;
		b += (GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl)) * 2;
		// The others are counted once
		r += GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc)
		   + GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br);
		g += GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc)
		   + GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br);
		b += GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc)
		   + GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br);
	} else if (mv_right) {
		// Movement to the right, weight right side colour twice
		r += (GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br)) * 2;
		g += (GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br)) * 2;
		b += (GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br)) * 2;
		// The others are counted once
		r += GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc)
		   + GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl);
		g += GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc)
		   + GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl);
		b += GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc)
		   + GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl);
	} else {
		// No x-movement, weight centre colour twice
		r += (GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc)) * 2;
		g += (GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc)) * 2;
		b += (GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc)) * 2;
		// The others are counted once
		r += GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl)
		   + GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br);
		g += GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl)
		   + GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br);
		b += GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl)
		   + GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br);
	}

	/* --- Y-Movement --- */
	if (mv_up) {
		// Movement upwards, weight top side colour twice
		r += (GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr)) * 2;
		g += (GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr)) * 2;
		b += (GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr)) * 2;
		// The others are counted once
		r += GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr)
		   + GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br);
		g += GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr)
		   + GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br);
		b += GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr)
		   + GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br);
	} else if (mv_down) {
		// Movement downwards, weight bottom side colour twice
		r += (GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br)) * 2;
		g += (GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br)) * 2;
		b += (GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br)) * 2;
		// The others are counted once
		r += GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr)
		   + GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr);
		g += GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr)
		   + GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr);
		b += GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr)
		   + GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr);
	} else {
		// No y-movement, weight middle colour twice
		r += (GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr)) * 2;
		g += (GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr)) * 2;
		b += (GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr)) * 2;
		// The others are counted once
		r += GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr)
		   + GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br);
		g += GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr)
		   + GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br);
		b += GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr)
		   + GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br);
	}


	/* I know this looks weird, but what we now have is some kind of summed
	 * matrix, which is always the same:
	 * Let's assume that xv and yv are both 0.0, so no movement is happening.
	 * The result is: (In counted times)
	 * 2|3|2  ( =  7)
	 * -+-+-
	 * 3|4|3  ( = 10)
	 * -+-+-
	 * 2|3|2  ( =  7)
	 *          = 24
	 * And it is always 24, no matter which movement combination you try
	 */

	r /= 24;
	g /= 24;
	b /= 24;

	return makecol(r > 0xff ? 0xff : r,
	               g > 0xff ? 0xff : g,
	               b > 0xff ? 0xff : b);
}
Пример #16
0
/***********************************************************************
* plugin main ppu thread
***********************************************************************/
static void vsh_menu_thread(uint64_t arg)
{
    #ifdef DEBUG
    dbg_init();
    dbg_printf("programstart:\n");
    #endif

    uint16_t oldpad = 0, curpad = 0;
    CellPadData pdata;

    // wait for XMB, feedback
    sys_timer_sleep(13);

    //vshtask_notify("sprx running...");

    play_rco_sound("system_plugin", "snd_trophy");

    #ifdef HAVE_STARFIELD
    init_once(/* stars */);
    #endif

    // custom bg_color init
    a = GET_A(bg_color_menu[1]);
    r = GET_R(bg_color_menu[1]);
    g = GET_G(bg_color_menu[1]);
    b = GET_B(bg_color_menu[1]);

    while(1)
    {
        // if VSH Menu is running, we get pad data over our MyPadGetData()
        // else, we use the vsh pad_data struct
        if(menu_running)
            MyPadGetData(0, &pdata);
        else
            VSHPadGetData(&pdata);

        // if pad_data and we are in XMB(vshmain_EB757101() == 0)
        if((pdata.len > 0)
        && (vshmain_EB757101() == 0)
        )
        {
            curpad = (pdata.button[2] | (pdata.button[3] << 8));

            if((curpad & PAD_SELECT) && (curpad != oldpad))
            {
                switch(menu_running)
                {
                    // VSH Menu not running, start VSH Menu
                    case 0:
                      // main view and start on first entry 
                      view = line = 0;

                      //
                      pause_RSX_rendering();

                      // create VSH Menu heap memory from memory container 1("app")
                      create_heap(64);       // 64 MB

                      // initialize VSH Menu graphic (init drawing context, alloc buffers, blah, blah, blah...)
                      init_graphic();

                      // stop vsh pad
                      start_stop_vsh_pad(0);

                      // set menu_running
                      menu_running = 1;

                      break;

                    // VSH Menu is running, stop VSH Menu
                    case 1:
                      stop_VSH_Menu();

                      // restart vsh pad
                      start_stop_vsh_pad(1);

                      break;
                }

                oldpad = 0;
                sys_timer_usleep(300000);
            }


          // VSH Menu is running, draw menu / check pad
          if(menu_running)
          {
                #ifdef DEBUG
                dbg_printf("%p\n", pdata);
                #endif

                draw_frame(&pdata);

                flip_frame();

                if(curpad != oldpad)
                {

                    if(curpad & PAD_UP)
                    {
                        if(line <= 0){
                            line = 0;
                        }else{
                            line--;
                            play_rco_sound("system_plugin", "snd_cursor");
                        }
                    }

                    if(curpad & PAD_DOWN)
                    {
                        if(line >= max_menu[view]-1){
                            line = max_menu[view]-1;
                        }else{
                            line++;
                            play_rco_sound("system_plugin", "snd_cursor");
                        }
                    }

                    if(curpad & PAD_LEFT
                    || curpad & PAD_RIGHT) do_leftright_action(curpad);

                    if(curpad & PAD_CROSS) do_menu_action();

                }

                // ...

                sys_timer_usleep(30);

            } // end VSH Menu is running

            oldpad = curpad;
        }else{
            oldpad = 0;
        }
    }

    #ifdef DEBUG
    dbg_fini();
    #endif
    sys_ppu_thread_exit(0);
}
Пример #17
0
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
  if (texture)
  {
    glActiveTexture(GL_TEXTURE0);
    texture->LoadToGPU();
    glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());
    glEnable(GL_TEXTURE_2D);
  }
  else
    glDisable(GL_TEXTURE_2D);

  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);          // Turn Blending On

  VerifyGLState();

  GLfloat col[4][4];
  GLfloat ver[4][3];
  GLfloat tex[4][2];
  GLubyte idx[4] = {0, 1, 3, 2};        //determines order of triangle strip

  g_Windowing.EnableGUIShader(SM_TEXTURE);

  GLint posLoc   = g_Windowing.GUIShaderGetPos();
  GLint colLoc   = g_Windowing.GUIShaderGetCol();
  GLint tex0Loc  = g_Windowing.GUIShaderGetCoord0();

  glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, 0, ver);
  glVertexAttribPointer(colLoc,  4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col);
  glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);

  glEnableVertexAttribArray(posLoc);
  glEnableVertexAttribArray(tex0Loc);
  glEnableVertexAttribArray(colLoc);

  for (int i=0; i<4; i++)
  {
    // Setup Colour Values
    col[i][0] = (GLubyte)GET_R(color);
    col[i][1] = (GLubyte)GET_G(color);
    col[i][2] = (GLubyte)GET_B(color);
    col[i][3] = (GLubyte)GET_A(color);
  }

  // Setup vertex position values
  // ver[0][3] = ver[1][3] = ver[2][3] = ver[3][3] = 0.0f; // FIXME, ver has only 3 elements - this is not correct
  ver[0][0] = ver[3][0] = rect.x1;
  ver[0][1] = ver[1][1] = rect.y1;
  ver[1][0] = ver[2][0] = rect.x2;
  ver[2][1] = ver[3][1] = rect.y2;

  // Setup texture coordinates
  CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
  tex[0][0] = tex[3][0] = coords.x1;
  tex[0][1] = tex[1][1] = coords.y1;
  tex[1][0] = tex[2][0] = coords.x2;
  tex[2][1] = tex[3][1] = coords.y2;

  glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

  glDisableVertexAttribArray(posLoc);
  glDisableVertexAttribArray(colLoc);
  glDisableVertexAttribArray(tex0Loc);

  g_Windowing.DisableGUIShader();

  if (texture)
    glDisable(GL_TEXTURE_2D);
}
Пример #18
0
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
    if (texture)
    {
        glActiveTexture(GL_TEXTURE0);
        texture->LoadToGPU();
        glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());
    }

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);          // Turn Blending On

    VerifyGLState();

    GLubyte col[4][4];
    GLfloat ver[4][3];
    GLfloat tex[4][2];
    GLubyte idx[4] = {0, 1, 3, 2};        //determines order of triangle strip

    if (texture)
        g_Windowing.EnableGUIShader(SM_TEXTURE);
    else
        g_Windowing.EnableGUIShader(SM_DEFAULT);

    GLint posLoc   = g_Windowing.GUIShaderGetPos();
    GLint colLoc   = g_Windowing.GUIShaderGetCol();
    GLint tex0Loc  = g_Windowing.GUIShaderGetCoord0();

    glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, 0, ver);
    if(colLoc >= 0)
        glVertexAttribPointer(colLoc,  4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col);
    if (texture)
        glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);

    glEnableVertexAttribArray(posLoc);
    if (texture)
        glEnableVertexAttribArray(tex0Loc);
    if(colLoc >= 0)
        glEnableVertexAttribArray(colLoc);

    for (int i=0; i<4; i++)
    {
        // Setup Colour Values
        col[i][0] = (GLubyte)GET_R(color);
        col[i][1] = (GLubyte)GET_G(color);
        col[i][2] = (GLubyte)GET_B(color);
        col[i][3] = (GLubyte)GET_A(color);
    }

    // Setup vertex position values
#define ROUND_TO_PIXEL(x) (float)(MathUtils::round_int(x))
    ver[0][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y1));
    ver[0][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y1));
    ver[0][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y1));
    ver[1][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y1));
    ver[1][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y1));
    ver[1][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y1));
    ver[2][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y2));
    ver[2][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y2));
    ver[2][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y2));
    ver[3][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y2));
    ver[3][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y2));
    ver[3][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y2));
    if (texture)
    {
        // Setup texture coordinates
        CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
        tex[0][0] = tex[3][0] = coords.x1;
        tex[0][1] = tex[1][1] = coords.y1;
        tex[1][0] = tex[2][0] = coords.x2;
        tex[2][1] = tex[3][1] = coords.y2;
    }
    glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

    glDisableVertexAttribArray(posLoc);
    if(colLoc >= 0)
        glDisableVertexAttribArray(colLoc);
    if (texture)
        glDisableVertexAttribArray(tex0Loc);

    g_Windowing.DisableGUIShader();
}
Пример #19
0
/**
 * Update the episodic memories for a given ape.
 * This is based upon a fading memory model in which older memories
 * are replaced by newer ones.  Each memory has an associated affect
 * value indicating its emotional impact, and this fades over time.
 *
 * The rate of fading is genetically regulated, with different rates
 * for memories with positive and negative affect.
 * This facilitates optimistic/pessimistic and forgetful/memorable
 * type personalities.
 *
 * The fading memory model may not be strictly realistic, and might
 * be replaced by something else in future.
 * @param local_sim pointer to the simulation
 * @param local pointer to the ape
 */
void episodic_cycle(noble_simulation * local_sim, noble_being * local)
{
    n_int i;
    episodic_memory * local_episodic = GET_EPI(local_sim, local);

    if (!local_episodic) return;

    for (i=0; i<EPISODIC_SIZE; i++)
    {
        if (local_episodic[i].event == 0) continue;

        /** remove intentions which are outdated */
        if (local_episodic[i].event >= EVENT_INTENTION)
        {
            /** is this my intention, or someone else's? */
            if ((local_episodic[i].first_name[BEING_MEETER]==GET_NAME_GENDER(local_sim,local)) &&
                    (local_episodic[i].family_name[BEING_MEETER]==GET_NAME_FAMILY2(local_sim,local)))
            {

                if (local_episodic[i].date[0] < local_sim->land->date[0])
                {
                    local_episodic[i].event = 0;
                    continue;
                }
                else
                {
                    if (local_episodic[i].time < local_sim->land->time)
                    {
                        local_episodic[i].event = 0;
                        continue;
                    }
                }
            }
            episodic_intention_update(local_sim,local,i);
        }

        /** fade towards EPISODIC_AFFECT_ZERO */
        if (local_episodic[i].affect < EPISODIC_AFFECT_ZERO)
        {
            /** negative memories fade */
            if (EPISODIC_AFFECT_ZERO - local_episodic[i].affect > 16)
            {
                local_episodic[i].affect+=(1+GENE_NEGATIVE_AFFECT_FADE(GET_G(local)));
            }
            else
            {
                local_episodic[i].affect++;
            }
        }
        else
        {
            if (local_episodic[i].affect > EPISODIC_AFFECT_ZERO)
            {
                /** positive memories fade */
                if (local_episodic[i].affect - EPISODIC_AFFECT_ZERO > 16)
                {
                    local_episodic[i].affect-=(1+GENE_POSITIVE_AFFECT_FADE(GET_G(local)));
                }
                else
                {
                    local_episodic[i].affect--;
                }
            }
        }
    }
}
Пример #20
0
void CGUITextureD3D::Begin(color_t color)
{
  int unit = 0;
  CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
  LPDIRECT3DDEVICE9 p3DDevice = g_Windowing.Get3DDevice();

  texture->LoadToGPU();
  if (m_diffuse.size())
    m_diffuse.m_textures[0]->LoadToGPU();
  // Set state to render the image
  texture->BindToUnit(unit);
  p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP  , D3DTOP_MODULATE );
  p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE   );
  p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_DIFFUSE   );
  p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP  , D3DTOP_MODULATE );
  p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE   );
  p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE   );
  unit++;

  if (m_diffuse.size())
  {
    m_diffuse.m_textures[0]->BindToUnit(1);
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE   );
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CURRENT   );
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP  , D3DTOP_MODULATE );
    p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE   );
    p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_CURRENT   );
    p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP  , D3DTOP_MODULATE );
    unit++;
  }

  if(g_Windowing.UseLimitedColor())
  {
    m_col = D3DCOLOR_RGBA(GET_R(color) * (235 - 16) / 255
                        , GET_G(color) * (235 - 16) / 255
                        , GET_B(color) * (235 - 16) / 255
                        , GET_A(color));
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP  , D3DTOP_ADD );
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_CURRENT) ;
    p3DDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_RGBA(16,16,16, 0) );
    p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_TFACTOR );
    unit++;
  }
  else
    m_col = color;

  p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_DISABLE);
  p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

  p3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
  p3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
  p3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
  p3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
  p3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
  p3DDevice->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE );
  p3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
  p3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  p3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
  p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
  p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
  p3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE);

  p3DDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 );
}
Пример #21
0
void CGUITextureGLES::Begin(color_t color)
{
    CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
    glActiveTexture(GL_TEXTURE0);
    texture->LoadToGPU();
    if (m_diffuse.size())
        m_diffuse.m_textures[0]->LoadToGPU();

    glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());

    // Setup Colors
    for (int i = 0; i < 4; i++)
    {
        m_col[i][0] = (GLubyte)GET_R(color);
        m_col[i][1] = (GLubyte)GET_G(color);
        m_col[i][2] = (GLubyte)GET_B(color);
        m_col[i][3] = (GLubyte)GET_A(color);
    }

    bool hasAlpha = m_texture.m_textures[m_currentFrame]->HasAlpha() || m_col[0][3] < 255;

    if (m_diffuse.size())
    {
        if (m_col[0][0] == 255 && m_col[0][1] == 255 && m_col[0][2] == 255 && m_col[0][3] == 255 )
        {
            g_Windowing.EnableGUIShader(SM_MULTI);
        }
        else
        {
            g_Windowing.EnableGUIShader(SM_MULTI_BLENDCOLOR);
        }

        hasAlpha |= m_diffuse.m_textures[0]->HasAlpha();

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, m_diffuse.m_textures[0]->GetTextureObject());

        GLint tex1Loc = g_Windowing.GUIShaderGetCoord1();
        glVertexAttribPointer(tex1Loc, 2, GL_FLOAT, 0, 0, m_tex1);
        glEnableVertexAttribArray(tex1Loc);

        hasAlpha = true;
    }
    else
    {
        if ( hasAlpha )
        {
            g_Windowing.EnableGUIShader(SM_TEXTURE);
        }
        else
        {
            g_Windowing.EnableGUIShader(SM_TEXTURE_NOBLEND);
        }
    }

    GLint posLoc  = g_Windowing.GUIShaderGetPos();
    GLint colLoc  = g_Windowing.GUIShaderGetCol();
    GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();

    glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, m_vert);
    if(colLoc >= 0)
        glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_col);
    glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, m_tex0);

    glEnableVertexAttribArray(posLoc);
    if(colLoc >= 0)
        glEnableVertexAttribArray(colLoc);
    glEnableVertexAttribArray(tex0Loc);

    if ( hasAlpha )
    {
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glEnable( GL_BLEND );
    }
    else
    {
        glDisable(GL_BLEND);
    }
}
Пример #22
0
void CParticle::render()
{
    // If particle isn't alive, then there is nothing to render
    if(isAlive() == false)
        return;

    // Can't render a particle that does not have a valid texture
    if(mTexture.getId() == TEXTURE_NOT_LOADED)
        return;

    // This OpenGL functions makes the Z-buffer "read only".  That means OpenGL will
    // use current z-buffer values to determine if a particle should be rendered or not, BUT,
    // if it does render a particle it will NOT set any z-buffer values.  Why do we do this?
    // Well we want the particles to blend, and not cover each other up.  So now we can
    // render them in the same Z-depth and they will blend, but at the same time, they
    // won't render over top of anything with a lesser Z-depth
    glDepthMask(false);

    BYTE red, green, blue;

    // Set the color based on the life of the particle
    if(mLife < 1.0f)
    {
        // If the particle has less than a second to live, we will
        // decrease the R, G, and B value of it's color by multipling
        // by "mLife", this will in turn fade the particle to black, which
        // is our applications background color
        red = BYTE(GET_R(mColor) * mLife);
        green = BYTE(GET_G(mColor) * mLife);
        blue = BYTE(GET_B(mColor) * mLife);
    }
    else
    {
        // Just get the RGB components of the color
        red = GET_R(mColor);
        green = GET_G(mColor);
        blue = GET_B(mColor);
    }

    // Set the color for rendering
    glColor3ub(red, green, blue);

    // Set the texture for rendering
    mTexture.select();

    glPushMatrix();

    // Move to the world position of where to draw the particle
    glTranslatef(mPos.x, mPos.y, mPos.z);

    float halfSize = mSize * 0.5f;

    // Draw the particle
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-halfSize, halfSize, 0.0f); // Top left vertex

    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-halfSize, -halfSize, 0.0f); // Bottom left vertex

    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(halfSize, -halfSize, 0.0f); // Bottom right vertex

    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(halfSize, halfSize, 0.0f); // Top right vertex
    glEnd();

    glPopMatrix();

    glDepthMask(true); // Put the Z-buffer back into it's normal "Z-read and Z-write" state
}