Ejemplo n.º 1
0
 const SUCCESS colorChange(const SDL_Keysym &key)
 {
     switch(key.scancode)
     {
     default:
         return SUCCEEDED;
     case SDL_SCANCODE_Q:
         col.R()++;
         break;
     case SDL_SCANCODE_W:
         col.G()++;
         break;
     case SDL_SCANCODE_E:
         col.B()++;
         break;
     case SDL_SCANCODE_R:
         col.A()++;
         break;
     case SDL_SCANCODE_A:
         col.R()--;
         break;
     case SDL_SCANCODE_S:
         col.G()--;
         break;
     case SDL_SCANCODE_D:
         col.B()--;
         break;
     case SDL_SCANCODE_F:
         col.A()--;
         break;
     }
     
     ren.setColor(col);
     return SUCCEEDED;
 }
inline static Color RandColor( Color c0, Color c1 )
{
	// We might want to find min and max of each channel rather than assuming c0 <= c1
	return Color(
		s_RNG.NextFloat( c0.R(), c1.R()),
		s_RNG.NextFloat( c0.G(), c1.G()),
		s_RNG.NextFloat( c0.B(), c1.B()),
		s_RNG.NextFloat( c0.A(), c1.A())
		);
}
Ejemplo n.º 3
0
inline Color ColorClamp(const Color &col) {
  Color ret;
  ret = col;

  if ( col.R() > 1.0f )
    ret.R(1.0f);

  if ( col.G() > 1.0f )
    ret.G(1.0f);

  if ( col.B() > 1.0f )
    ret.B(1.0f);

  return ret;
}
Ejemplo n.º 4
0
void Context :: GetBooleanv(GLenum pname, GLboolean *params) {
	switch (pname) {
	case GL_LIGHT_MODEL_TWO_SIDE:
		params[0] = m_TwoSidedLightning;
		break;

	case GL_COLOR_WRITEMASK:
		{
			Color mask = m_RasterizerState.GetColorMask();
			params[0] = mask.R() != 0;
			params[1] = mask.G() != 0;
			params[2] = mask.B() != 0;
			params[3] = mask.A() != 0;
		}
		break;

	case GL_DEPTH_WRITEMASK:
		params[0] = m_RasterizerState.GetDepthMask();
		break;

	case GL_SAMPLE_COVERAGE_INVERT:
		params[0] = m_RasterizerState.GetSampleCoverageInvert();
		break;

	default:
		RecordError(GL_INVALID_ENUM);
		return;
	}
}
Ejemplo n.º 5
0
 void operator-=(const Color &rhs)
 {
     m_col.c.r -= rhs.R();
     m_col.c.g -= rhs.G();
     m_col.c.b -= rhs.B();
     m_col.c.a -= rhs.A();
 }
Ejemplo n.º 6
0
 void operator*=(const Color &rhs)
 {
     m_col.c.r *= rhs.R();
     m_col.c.g *= rhs.G();
     m_col.c.b *= rhs.B();
     m_col.c.a *= rhs.A();
 }
Ejemplo n.º 7
0
void Raytracer::RenderPart(int _x, int _y, int _width, int _height)
{
	for (int i = 0; i < 200; i++)
	{
		for (int x = _x; x < _x + _width; x++)
		{
			for (int y = _y; y < _y + _height; y++)
			{
				int pixelIndex = (x + m_Width * y) * 4;
				Ray current = GetRay(x, y);

				Color col = ReadColorAt(x, y);
				float factor = 1.0f - 1.0f / i;
				col = col * factor + m_pScene->Intersect(current, 3) * (1.0f - factor);

				sf::Color newCol((sf::Uint8)(col.R() * 255), (sf::Uint8)(col.G() * 255), (sf::Uint8)(col.B() * 255), 255);

				m_Pixels[pixelIndex + 0] = newCol.r;
				m_Pixels[pixelIndex + 1] = newCol.g;
				m_Pixels[pixelIndex + 2] = newCol.b;
				m_Pixels[pixelIndex + 3] = newCol.a;
			}
		}
	}
}
Ejemplo n.º 8
0
    void operator+=(const Color &rhs)
    {
        m_col.c.r += rhs.R();
        m_col.c.g += rhs.G();
        m_col.c.b += rhs.B();
        m_col.c.a += rhs.A();

    }
Ejemplo n.º 9
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// GenerateFillVertices()
//
////////////////////////////////////////////////////////////////////////////////////////////////////
void CVertexGenerator::GenerateFillVertices( const WinRect & rectToFill, const bool bSetStream, Color fillColour )
{
    D3DCOLOR d3dColor = D3DCOLOR_RGBA(	(DWORD) (fillColour.R() * 255),
                                        (DWORD) (fillColour.G() * 255),
                                        (DWORD) (fillColour.B() * 255),
                                        255 );
    GenerateFillVerticesD3DColor( rectToFill, bSetStream, d3dColor );
}
Ejemplo n.º 10
0
void PhotonMap::ScalePhotons(const float scaleFactor)
{
	for(int index = 0; index < (int) m_photons.size(); index++)
	{
		Color power = m_photons[index].Power();
		power.R() *= scaleFactor; 
		power.G() *= scaleFactor;
		power.B() *= scaleFactor;

		m_photons[index].Power(power);
	}
}
Ejemplo n.º 11
0
Color PhotonMap::GetRadianceEstimate(const int N, const float maxDistance, Point3 location, Vector3 normal)
{
    float R = 0; 
    float G = 0; 
    float B = 0;

    vector<PhotonDistPair> nearest = GetNearestNPhotons(N, maxDistance, location, normal);

    if(nearest.size() == 0)
    {
        return Color(0.0, 0.0, 0.0);
    }

    // get the radius of the furthest photon
    double r = nearest.front().m_Distance;

 
    for(int index = 0; index < nearest.size(); ++index)
    {
        const Photon* p = nearest[index].m_pPhoton;
        

        Color power = p->Power();
        Vector3 photonDir = p->Direction(); 

        double radius = nearest[index].m_Distance;
        double weight = (m_CausticsMap) ? (r - radius)/radius : 1;//smoothstep(0,1,1-radius/r);

        R += power.R() * weight;
        G += power.G() * weight;
        B += power.B() * weight;
        //std::cout << weight << std::endl;

     }

    // filter?
    float densityEstimate = (m_CausticsMap) ? N/(PI*r*r) : 1;

    R *= densityEstimate;
    G *= densityEstimate;
    B *= densityEstimate;

    return Color(R,G,B);
}
Ejemplo n.º 12
0
sf::Color SfmlConverter::GetSFColor(const Color& color)
{
	return sf::Color(color.R(),color.G(),color.B(),color.Alpha());
}
Ejemplo n.º 13
0
	inline sf::Color RedToSFMLColor(const Color &pColor){
		return sf::Color(static_cast<u8>(pColor.R() * 255), 
						 static_cast<u8>(pColor.G() * 255), 
						 static_cast<u8>(pColor.B() * 255),
						 static_cast<u8>(pColor.A() * 255));
	}
Ejemplo n.º 14
0
void QTRenderer::DrawRectangle(const Pointf& point, const Sizef& size, const Color& outlineColor, float thickness) {
    QPen p(QColor(outlineColor.R(),outlineColor.G(),outlineColor.B(),outlineColor.A()));
         p.setWidth((int)thickness);
    painter->setPen(p);
    painter->drawRect(point.X(),point.Y(),size.W(),size.H());
}
Ejemplo n.º 15
0
void QTRenderer::DrawFilledRectangle(const Pointf& point, const Sizef& size, const Color& fillColor)
{
    painter->fillRect(point.X(),point.Y(),size.W(),size.H(),QBrush(QColor(fillColor.R(),fillColor.G(),fillColor.B(),fillColor.A())));
}
Ejemplo n.º 16
0
// ===================
// Point lights
// ===================
void World::DoLightingPass(const PointLight& l)
{
    gbuffer.StartLightingPass();

    // Disable depth test.
    glDisable(GL_DEPTH_TEST);

    // Setup for lighting pass.
    glStencilFunc(GL_NOTEQUAL, 0, 0xFF);

    glEnable(GL_BLEND);

    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);

    // Bind pass 2 shader.
    Shader* lpassShader = &pointLightShader;
    Shader::Bind(lpassShader);

    // Activate gbuffer textures.
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetColorID());
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetNormalID());
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetPositionID());

    // Matrices
    Matrix pmat = cam.GetProjectionMatrix();
    Matrix vmat = cam.GetViewMatrix();

    lpassShader->SetParameter("projectionMatrix", &pmat[0][0]);
    lpassShader->SetParameter("viewMatrix", &vmat[0][0]);
    lpassShader->SetParameter("screenSize", WINDOW_WIDTH, WINDOW_HEIGHT);

    // Set the eye position to the camera position.
    Vector3 cpos = cam.GetPosition();
    lpassShader->SetParameter("eyePosition", cpos.x, cpos.y, cpos.z);
    lpassShader->SetParameter("farClipDistance", cam.GetFarClippingPlane());

    // Texture locations
    lpassShader->SetParameter("difftex", 0);
    lpassShader->SetParameter("normtex", 1);
    lpassShader->SetParameter("postex", 2);

    // Draw point lights.
    Matrix lmat = l.GetMatrix();
    lpassShader->SetParameter("modelMatrix", &lmat[0][0]);

    const Vector3& pos = l.GetPosition();
    lpassShader->SetParameter("lightPos", pos.x, pos.y, pos.z);

    // Itensity.
    lpassShader->SetParameter("ambientIntensity", l.GetAmbientIntensity());
    lpassShader->SetParameter("diffuseIntensity", l.GetDiffuseIntensity());

    // Attenuation.
    lpassShader->SetParameter("attenuationConstant", l.GetAttenuationConstant());
    lpassShader->SetParameter("attenuationLinear", l.GetAttenuationLinear());
    lpassShader->SetParameter("attenuationExponential", l.GetAttenuationExponential());

    Color diffuseColor = l.GetColor();
    lpassShader->SetParameter("lightColor", diffuseColor.R(), diffuseColor.G(), diffuseColor.B());

    pointLightMesh.Draw();

    glCullFace(GL_BACK);
    glDisable(GL_BLEND);
}
Ejemplo n.º 17
0
int* OilFilter::procImage() {
	int *originPixels = new int[width * height];
	memcpy(originPixels, pixels, width * height * sizeof(int));

	int rHis[OIL_FILTER_LEVEL], gHis[OIL_FILTER_LEVEL], bHis[OIL_FILTER_LEVEL];

	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			memset(rHis, 0, OIL_FILTER_LEVEL * sizeof(int));
			memset(gHis, 0, OIL_FILTER_LEVEL * sizeof(int));
			memset(bHis, 0, OIL_FILTER_LEVEL * sizeof(int));

			int rowOffset, colOffset;
			for (int row = -this->oilRange; row < this->oilRange; row++) {
				rowOffset = y + row;
				if (rowOffset >= 0 && rowOffset < height) {
					for (int col = -this->oilRange; col < this->oilRange; col++) {
						colOffset = x + col;
						if (colOffset >= 0 && colOffset < width) {
							Color color = originPixels[rowOffset * width + colOffset];
							int r = color.R();
							int g = color.G();
							int b = color.B();

							rHis[r]++;
							gHis[g]++;
							bHis[b]++;
						}
					}
				}
			}

			int maxR = 0, maxG = 0, maxB = 0;
			for (int i = 1; i < OIL_FILTER_LEVEL; i++) {
				if (rHis[i] > rHis[maxR]) {
					maxR = i;
				}
				if (gHis[i] > gHis[maxG]) {
					maxG = i;
				}
				if (bHis[i] > bHis[maxB]) {
					maxB = i;
				}
			}
			if (rHis[maxR] != 0 && gHis[maxG] != 0 && bHis[maxB] != 0) {
				int finalR = maxR;
				int finalG = maxG;
				int finalB = maxB;

				finalR = min(255, max(0, finalR));
				finalG = min(255, max(0, finalG));
				finalB = min(255, max(0, finalB));

				pixels[y * width + x] = RGB2Color(finalR, finalG, finalB);
			}
		}
	}

	delete [] originPixels;

	return pixels;
}