本文整理汇总了C++中Color4类的典型用法代码示例。如果您正苦于以下问题:C++ Color4类的具体用法?C++ Color4怎么用?C++ Color4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Color4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: glPushMatrix
// ----------------------------------------------------------------
// Name: renderRectangle
// Description: 根据参数TRectanglef提供的参数绘制矩形
// Return Value: void
// ----------------------------------------------------------------
void Helper::renderRectangle( const TRectanglef& rect,
Color4 color, bool isEmpty )
{
float left = rect.m_Left;
float right = rect.m_Right;
float bottom = rect.m_Bottom;
float top = rect.m_Top;
glPushMatrix();
{
glColor4f( color.r(), color.g(), color.b(), color.a() );
glLineWidth(2.0);
if( isEmpty )
{
glBegin(GL_LINE_STRIP);
glVertex3f(left, bottom, 0.0);
glVertex3f(right, bottom, 0.0);
glVertex3f(right, top, 0.0);
glVertex3f(left, top, 0.0);
glVertex3f(left, bottom, 0.0);
glEnd();
}
else
{
glBegin(GL_QUADS);
glVertex3f(left, bottom, 0.0);
glVertex3f(right, bottom, 0.0);
glVertex3f(right, top, 0.0);
glVertex3f(left, top, 0.0);
glEnd();
}
glLineWidth(1.0);
} glPopMatrix();
}
示例2: Convert
/* ------------------------------------------------------- */
D3DCOLORVALUE DX::Convert(const Color4& color)
{
D3DCOLORVALUE result;
result.a = color.A();
result.r = color.R();
result.g = color.G();
result.b = color.B();
return result;
}
示例3: toColor4ub
Color4ub toColor4ub(const Color4& _color)
{
using gex::color::clamp;
return Color4ub(
clamp(int(255*_color.r()),0,255),
clamp(int(255*_color.g()),0,255),
clamp(int(255*_color.b()),0,255),
clamp(int(255*_color.a()),0,255));
}
示例4:
void D3D10System::ClearColorBuffer(DWORD color)
{
Color4 floatColor;
floatColor.MakeFromRGBA(color);
D3D10Texture *d3dTex = static_cast<D3D10Texture*>(curRenderTarget);
if(d3dTex)
d3d->ClearRenderTargetView(d3dTex->renderTarget, floatColor.ptr);
else
d3d->ClearRenderTargetView(swapRenderView, floatColor.ptr);
}
示例5: glBegin
void Board::draw()
{
//doing this without textures just to make this work.
//this should be chopped into squares for tiling the texture
//or there's a gl function for doing so. whatevs
Color4 myColor = ColorScheme::GREEN;
glBegin(GL_QUADS);
glColor4fv(myColor.toArray());
glVertex2f(_center.x - Game::HBOUND/2.0f, _center.y - Game::VBOUND/2.0f);
glVertex2f(_center.x + Game::HBOUND/2.0f, _center.y - Game::VBOUND/2.0f);
glVertex2f(_center.x + Game::HBOUND/2.0f, _center.y + Game::VBOUND/2.0f);
glVertex2f(_center.x - Game::HBOUND/2.0f, _center.y + Game::VBOUND/2.0f);
glEnd();
}
示例6: TextureRef
void CurvePreview::Redraw()
{
if (!mCurve)
return;
TextureRef texture = mSprite->GetTexture();
if (!texture || texture->GetSize() != layout->GetSize())
{
texture = TextureRef(layout->GetSize(), PixelFormat::R8G8B8A8, Texture::Usage::RenderTarget);
mSprite->SetTexture(texture);
mSprite->SetTextureSrcRect(RectI(Vec2I(), texture->GetSize()));
}
const Color4 backColor(120, 120, 120, 255);
const Color4 curveColor(0, 255, 0, 255);
Camera prevCamera = o2Render.GetCamera();
Camera currCamera; currCamera.SetRect(mCurve->GetRect());
currCamera.SetScale(currCamera.GetScale().InvertedY());
o2Render.SetRenderTexture(texture);
o2Render.SetCamera(currCamera);
o2Render.Clear(backColor);
static Vector<Vertex2> buffer;
buffer.Clear();
auto curveColorHex = curveColor.ARGB();
auto& keys = mCurve->GetKeys();
for (auto& key : keys)
{
buffer.Add(Vertex2(key.position, key.value, curveColorHex, 0, 0));
auto points = key.GetApproximatedPoints();
for (int i = 0; i < key.GetApproximatedPointsCount(); i++)
buffer.Add(Vertex2(points[i], curveColorHex, 0, 0));
o2Render.DrawAAPolyLine(buffer.Data(), buffer.Count(), 2);
}
o2Render.UnbindRenderTexture();
o2Render.SetCamera(prevCamera);
}
示例7: SetSpecularColor
GLvoid Material::SetSpecularColor(GLenum face, const Color4& c)
{
switch (face)
{
case GL_FRONT:
_front_specular.r() = c.r();
_front_specular.g() = c.g();
_front_specular.b() = c.b();
_front_specular.a() = c.a();
break;
case GL_BACK:
_back_specular.r() = c.r();
_back_specular.g() = c.g();
_back_specular.b() = c.b();
_back_specular.a() = c.a();
break;
case GL_FRONT_AND_BACK:
_front_specular.r() = c.r();
_front_specular.g() = c.g();
_front_specular.b() = c.b();
_front_specular.a() = c.a();
_back_specular.r() = c.r();
_back_specular.g() = c.g();
_back_specular.b() = c.b();
_back_specular.a() = c.a();
break;
}
}
示例8: Light
void Light(float colorOut[4], const float colorIn[4], Vec3 pos, Vec3 normal, float dots[4])
{
// could cache a lot of stuff, such as ambient, across vertices...
bool doShadeMapping = (gstate.texmapmode & 0x3) == 2;
if (!doShadeMapping && !(gstate.lightEnable[0]&1) && !(gstate.lightEnable[1]&1) && !(gstate.lightEnable[2]&1) && !(gstate.lightEnable[3]&1))
{
memcpy(colorOut, colorIn, sizeof(float) * 4);
return;
}
Color4 emissive;
emissive.GetFromRGB(gstate.materialemissive);
Color4 globalAmbient;
globalAmbient.GetFromRGB(gstate.ambientcolor);
globalAmbient.GetFromA(gstate.ambientalpha);
Vec3 norm = normal.Normalized();
Color4 in(colorIn);
Color4 ambient;
if (gstate.materialupdate & 1)
{
ambient = in;
}
else
{
ambient.GetFromRGB(gstate.materialambient);
ambient.a=1.0f;
}
Color4 diffuse;
if (gstate.materialupdate & 2)
{
diffuse = in;
}
else
{
diffuse.GetFromRGB(gstate.materialdiffuse);
diffuse.a=1.0f;
}
Color4 specular;
if (gstate.materialupdate & 4)
{
specular = in;
}
else
{
specular.GetFromRGB(gstate.materialspecular);
specular.a=1.0f;
}
float specCoef = getFloat24(gstate.materialspecularcoef);
norm.Normalize();
Vec3 viewer(gstate.viewMatrix[8], gstate.viewMatrix[9], gstate.viewMatrix[10]);
Color4 lightSum = globalAmbient * ambient + emissive;
// Try lights.elf - there's something wrong with the lighting
for (int l = 0; l < 4; l++)
{
// can we skip this light?
if ((gstate.lightEnable[l] & 1) == 0) // && !doShadeMapping)
continue;
GELightComputation comp = (GELightComputation)(gstate.ltype[l]&3);
GELightType type = (GELightType)((gstate.ltype[l]>>8)&3);
Vec3 toLight;
if (type == GE_LIGHTTYPE_DIRECTIONAL)
toLight = Vec3(gstate.lightpos[l]);
else
toLight = Vec3(gstate.lightpos[l]) - pos;
Vec3 dir = Vec3(gstate.lightdir[l]);
bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE);
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
float distance = toLight.Normalize();
float lightScale = 1.0f;
if (type != GE_LIGHTTYPE_DIRECTIONAL)
{
lightScale = 1.0f / (gstate.lightatt[l][0] + gstate.lightatt[l][1]*distance + gstate.lightatt[l][2]*distance*distance);
if (lightScale>1.0f) lightScale=1.0f;
}
float dot = toLight * norm;
// Clamp dot to zero.
if (dot < 0.0f) dot = 0.0f;
if (poweredDiffuse)
dot = powf(dot, specCoef);
//.........这里部分代码省略.........
示例9: c
void ParticleSystem::spawnFace
(const FaceScatter& faceScatter,
const ParseOBJ& parseObj,
const Color4& color,
const Matrix4& transform,
int materialIndex) {
const Color4unorm8 c(color.pow(1.0f / SmokeVolumeSet::PARTICLE_GAMMA));
Random rnd(10000, false);
m_particle.resize(0);
m_physicsData.resize(0);
AABox bounds;
for (ParseOBJ::GroupTable::Iterator git = parseObj.groupTable.begin(); git.isValid(); ++git) {
const shared_ptr<ParseOBJ::Group>& group = git->value;
for (ParseOBJ::MeshTable::Iterator mit = group->meshTable.begin(); mit.isValid(); ++mit) {
const shared_ptr<ParseOBJ::Mesh>& mesh = mit->value;
for (int f = 0; f < mesh->faceArray.size(); ++f) {
if (rnd.uniform() <= faceScatter.particlesPerFace) {
const ParseOBJ::Face& face = mesh->faceArray[f];
Particle& particle = m_particle.next();
PhysicsData& physicsData = m_physicsData.next();
// Use the average vertex as the position
Point3 vrt[10];
particle.position = Point3::zero();
for (int v = 0; v < face.size(); ++v) {
vrt[v] = (transform * Vector4(parseObj.vertexArray[face[v].vertex], 1.0f)).xyz();
particle.position += vrt[v];
}
particle.position /= float(face.size());
const Vector3& normal = (vrt[1] - vrt[0]).cross(vrt[2] - vrt[0]).direction();
particle.position += faceScatter.explodeDistance * normal;
particle.normal = normal;
particle.materialIndex = materialIndex;
particle.color = c;
particle.angle = rnd.uniform(0.0f, 2.0f) * pif();
particle.radius = min(faceScatter.maxRadius, faceScatter.radiusScaleFactor * pow((particle.position - vrt[0]).length(), faceScatter.radiusExponent));
particle.emissive = 0;
physicsData.angularVelocity = rnd.uniform(-1.0f, 1.0f) * (360.0f * units::degrees()) / (20.0f * units::seconds());
bounds.merge(particle.position);
}
} // face
} // mesh
} // group
// Center
if (faceScatter.moveCenterToOrigin) {
const Vector3& offset = -bounds.center();
for (int i = 0; i < m_particle.size(); ++i) {
m_particle[i].position += offset;
}
m_lastObjectSpaceAABoxBounds = bounds + offset;
} else {
m_lastObjectSpaceAABoxBounds = bounds;
}
}
示例10: getinitargs
static tuple getinitargs(Color4 const& c)
{
return make_tuple(c.getRed(),c.getGreen(),c.getBlue(),c.getAlpha());
}
示例11: SetAmbientColor
GLvoid Material::SetAmbientColor(GLenum face, const Color4& c)
{
SetAmbientColor(face, c.r(), c.g(), c.b(), c.a());
}
示例12: ConvertUInt
/* ------------------------------------------------------- */
unsigned int DX::ConvertUInt(const Color4& color)
{
return D3DCOLOR_ARGB(int(color.A()*255.0f), int(color.R()*255.0f), int(color.G()*255.0f), int(color.B()*255.0f));
}
示例13:
Color3::Color3( const Color4& c4) :
Tuple3<uchar_t>(c4.getRed(),c4.getGreen(),c4.getBlue()) {
}
示例14: DrawMesh
//[-------------------------------------------------------]
//[ Private virtual SRPDirectionalLighting functions ]
//[-------------------------------------------------------]
void SRPDirectionalLightingFixedFunctions::DrawMesh(Renderer &cRenderer, const SQCull &cCullQuery, const VisNode &cVisNode, SceneNode &cSceneNode, const MeshHandler &cMeshHandler, const Mesh &cMesh, const MeshLODLevel &cMeshLODLevel, VertexBuffer &cVertexBuffer)
{
// Get the fixed functions interface (when we're in here, we know that it must exist!)
FixedFunctions *pFixedFunctions = cRenderer.GetFixedFunctions();
// Set the current world matrix
pFixedFunctions->SetTransformState(FixedFunctions::Transform::World, cVisNode.GetWorldMatrix());
// Get buffers
IndexBuffer *pIndexBuffer = cMeshLODLevel.GetIndexBuffer();
const Array<Geometry> &lstGeometries = *cMeshLODLevel.GetGeometries();
// Bind buffers
cRenderer.SetIndexBuffer(pIndexBuffer);
pFixedFunctions->SetVertexBuffer(&cVertexBuffer);
// Draw mesh
for (uint32 nMat=0; nMat<cMeshHandler.GetNumOfMaterials(); nMat++) {
// Get mesh material
const Material *pMaterial = cMeshHandler.GetMaterial(nMat);
if (pMaterial && !pMaterial->GetEffect()) {
// Draw geometries
for (uint32 nGeo=0; nGeo<lstGeometries.GetNumOfElements(); nGeo++) {
// Is this geometry active and is it using the current used mesh material?
const Geometry &cGeometry = lstGeometries[nGeo];
if (cGeometry.IsActive() && nMat == cGeometry.GetMaterial()) {
// Transparent material?
static const String sOpacity = "Opacity";
const Parameter *pParameter = pMaterial->GetParameter(sOpacity);
if ((GetFlags() & TransparentPass) ? (pParameter && pParameter->GetValue1f() < 1.0f) : (!pParameter || pParameter->GetValue1f() >= 1.0f)) {
// Material change?
if (m_pCurrentMaterial != pMaterial) {
// Update current material
m_nMaterialChanges++;
m_pCurrentMaterial = pMaterial;
// Get opacity
const float fOpacity = pParameter ? pParameter->GetValue1f() : 1.0f;
if (fOpacity < 1) {
// Get and set source blend function
uint32 nValue = BlendFunc::SrcAlpha;
static const String sSrcBlendFunc = "SrcBlendFunc";
pParameter = pMaterial->GetParameter(sSrcBlendFunc);
if (pParameter) {
m_pRenderStates->SetAttribute("SrcBlendFunc", pParameter->GetParameterString());
nValue = m_pRenderStates->Get(RenderState::SrcBlendFunc);
}
cRenderer.SetRenderState(RenderState::SrcBlendFunc, nValue);
// Get and set destination blend function
nValue = BlendFunc::InvSrcAlpha;
static const String sDstBlendFunc = "DstBlendFunc";
pParameter = pMaterial->GetParameter(sDstBlendFunc);
if (pParameter) {
m_pRenderStates->SetAttribute("DstBlendFunc", pParameter->GetParameterString());
nValue = m_pRenderStates->Get(RenderState::DstBlendFunc);
}
cRenderer.SetRenderState(RenderState::DstBlendFunc, nValue);
}
// Setup cull mode
static const String sTwoSided = "TwoSided";
pParameter = pMaterial->GetParameter(sTwoSided);
cRenderer.SetRenderState(RenderState::CullMode, (pParameter && pParameter->GetValue1f()) == 1.0f ? Cull::None : Cull::CCW);
// Setup transparency and diffuse color
static const String sDiffuseColor = "DiffuseColor";
pParameter = pMaterial->GetParameter(sDiffuseColor);
if (pParameter) {
float fDiffuseColor[3] = { 1.0f, 1.0f, 1.0f };
pParameter->GetValue3f(fDiffuseColor[0], fDiffuseColor[1], fDiffuseColor[2]);
pFixedFunctions->SetColor(Color4(fDiffuseColor[0], fDiffuseColor[1], fDiffuseColor[2], fOpacity));
} else {
pFixedFunctions->SetColor(Color4(1.0f, 1.0f, 1.0f, fOpacity));
}
// Specular highlight
if (GetFlags() & NoSpecular) {
pFixedFunctions->SetMaterialState(FixedFunctions::MaterialState::Specular, Color4::Black.ToUInt32());
pFixedFunctions->SetMaterialState(FixedFunctions::MaterialState::Shininess, 0);
} else {
static const String sSpecularColor = "SpecularColor";
static const String sSpecularExponent = "SpecularExponent";
float fSpecularExponent = 45.0f;
Color4 cSpecularColor = Color4::White;
// First, get specular color - if it's 0, we don't have any specular at all
pParameter = pMaterial->GetParameter(sSpecularColor);
if (pParameter)
cSpecularColor = pParameter->GetValue3fv();
if (cSpecularColor != 0.0f) {
// Get specular exponent
pParameter = pMaterial->GetParameter(sSpecularExponent);
if (pParameter)
pParameter->GetValue1f(fSpecularExponent);
}
//.........这里部分代码省略.........
示例15: SetDiffuseColor
GLvoid Material::SetDiffuseColor(GLenum face, const Color4& c)
{
switch (face)
{
case GL_FRONT:
_front_diffuse.r() = c.r();
_front_diffuse.g() = c.g();
_front_diffuse.b() = c.b();
_front_diffuse.a() = c.a();
break;
case GL_BACK:
_back_diffuse.r() = c.r();
_back_diffuse.g() = c.g();
_back_diffuse.b() = c.b();
_back_diffuse.a() = c.a();
break;
case GL_FRONT_AND_BACK:
_front_diffuse.r() = c.r();
_front_diffuse.g() = c.g();
_front_diffuse.b() = c.b();
_front_diffuse.a() = c.a();
_back_diffuse.r() = c.r();
_back_diffuse.g() = c.g();
_back_diffuse.b() = c.b();
_back_diffuse.a() = c.a();
break;
}
}