Skip to content

Commit 7da0987

Browse files
authored
Use floats for colors internally. (#7650)
#changelog #gl
1 parent ef6df30 commit 7da0987

17 files changed

Lines changed: 319 additions & 231 deletions

libs/openFrameworks/app/ofAppNoWindow.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ class ofNoopRenderer: public ofBaseRenderer{
151151
void setDepthTest(bool){};
152152

153153
// color options
154-
void setColor(int r, int g, int b){}; // 0-255
155-
void setColor(int r, int g, int b, int a){}; // 0-255
156-
void setColor(const ofColor & color){};
157-
void setColor(const ofColor & color, int _a){};
158-
void setColor(int gray){}; // new set a color as grayscale with one argument
154+
void setColor(float r, float g, float b){}; // 0-1
155+
void setColor(float r, float g, float b, float a){}; // 0-1
156+
void setColor(const ofFloatColor & color){};
157+
void setColor(const ofFloatColor & color, float _a){};
158+
void setColor(float gray){}; // new set a color as grayscale with one argument
159159
void setHexColor( int hexColor ){}; // hex, like web 0xFF0033;
160160

161161
// bg color
162-
ofColor getBackgroundColor(){return ofColor(200);}
163-
void setBackgroundColor(const ofColor & color){}
162+
ofFloatColor getBackgroundColor(){return ofFloatColor(200.f/255.f);}
163+
void setBackgroundColor(const ofFloatColor & color){}
164164
bool getBackgroundAuto(){
165165
return true;
166166
}
167-
void background(const ofColor & c){};
167+
void background(const ofFloatColor & c){};
168168
void background(float brightness){};
169-
void background(int hexColor, float _a=255.0f){};
170-
void background(int r, int g, int b, int a=255){};
169+
void background(int hexColor, int _a=255){};
170+
void background(float r, float g, float b, float a=1.f){};
171171

172172
void setBackgroundAuto(bool bManual){}; // default is true
173173

libs/openFrameworks/gl/ofGLBaseTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class ofBaseGLRenderer: public ofBaseRenderer{
319319
/// \brief Set the global ambient light color.
320320
///
321321
/// \param c The color to set this renderer to use as ambient lighting.
322-
virtual void setGlobalAmbientColor(const ofColor& c)=0;
322+
virtual void setGlobalAmbientColor(const ofFloatColor& c)=0;
323323

324324
/// \brief Enable a light at a specific index.
325325
///

libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void ofGLProgrammableRenderer::draw(const ofPolyline & poly) const{
328328

329329
//----------------------------------------------------------
330330
void ofGLProgrammableRenderer::draw(const ofPath & shape) const{
331-
ofColor prevColor;
331+
ofFloatColor prevColor;
332332
if(shape.getUseShapeColor()){
333333
prevColor = currentStyle.color;
334334
}
@@ -848,33 +848,33 @@ glm::mat4 ofGLProgrammableRenderer::getCurrentOrientationMatrix() const {
848848
return matrixStack.getOrientationMatrix();
849849
}
850850
//----------------------------------------------------------
851-
void ofGLProgrammableRenderer::setColor(const ofColor & color){
851+
void ofGLProgrammableRenderer::setColor(const ofFloatColor & color){
852852
setColor(color.r,color.g,color.b,color.a);
853853
}
854854

855855
//----------------------------------------------------------
856-
void ofGLProgrammableRenderer::setColor(const ofColor & color, int _a){
856+
void ofGLProgrammableRenderer::setColor(const ofFloatColor & color, float _a){
857857
setColor(color.r,color.g,color.b,_a);
858858
}
859859

860860
//----------------------------------------------------------
861-
void ofGLProgrammableRenderer::setColor(int _r, int _g, int _b){
862-
setColor(_r, _g, _b, 255);
861+
void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b){
862+
setColor(_r, _g, _b, 1.f);
863863
}
864864

865865
//----------------------------------------------------------
866-
void ofGLProgrammableRenderer::setColor(int _r, int _g, int _b, int _a){
867-
ofColor newColor(_r,_g,_b,_a);
866+
void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b, float _a){
867+
ofFloatColor newColor(_r,_g,_b,_a);
868868
if(newColor!=currentStyle.color){
869869
currentStyle.color = newColor;
870870
if(currentShader){
871-
currentShader->setUniform4f(COLOR_UNIFORM,_r/255.,_g/255.,_b/255.,_a/255.);
871+
currentShader->setUniform4f(COLOR_UNIFORM,_r,_g,_b,_a);
872872
}
873873
}
874874
}
875875

876876
//----------------------------------------------------------
877-
void ofGLProgrammableRenderer::setColor(int gray){
877+
void ofGLProgrammableRenderer::setColor(float gray){
878878
setColor(gray, gray, gray);
879879
}
880880

@@ -883,7 +883,7 @@ void ofGLProgrammableRenderer::setHexColor(int hexColor){
883883
int r = (hexColor >> 16) & 0xff;
884884
int g = (hexColor >> 8) & 0xff;
885885
int b = (hexColor >> 0) & 0xff;
886-
setColor(r,g,b);
886+
setColor((float)r/255.f,(float)g/255.f,(float)b/255.f);
887887
}
888888

889889
//----------------------------------------------------------
@@ -898,7 +898,7 @@ void ofGLProgrammableRenderer::clear(){
898898

899899
//----------------------------------------------------------
900900
void ofGLProgrammableRenderer::clear(float r, float g, float b, float a) {
901-
glClearColor(r / 255., g / 255., b / 255., a / 255.);
901+
glClearColor(r, g, b, a);
902902
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
903903
}
904904

@@ -926,35 +926,39 @@ bool ofGLProgrammableRenderer::getBackgroundAuto(){
926926
}
927927

928928
//----------------------------------------------------------
929-
ofColor ofGLProgrammableRenderer::getBackgroundColor(){
929+
ofFloatColor ofGLProgrammableRenderer::getBackgroundColor(){
930930
return currentStyle.bgColor;
931931
}
932932

933933
//----------------------------------------------------------
934-
void ofGLProgrammableRenderer::setBackgroundColor(const ofColor & c){
934+
void ofGLProgrammableRenderer::setBackgroundColor(const ofFloatColor & c){
935935
currentStyle.bgColor = c;
936-
glClearColor(currentStyle.bgColor[0]/255., currentStyle.bgColor[1]/255., currentStyle.bgColor[2]/255., currentStyle.bgColor[3]/255.);
936+
glClearColor(currentStyle.bgColor[0], currentStyle.bgColor[1], currentStyle.bgColor[2], currentStyle.bgColor[3]);
937937
}
938938

939939
//----------------------------------------------------------
940-
void ofGLProgrammableRenderer::background(const ofColor & c){
940+
void ofGLProgrammableRenderer::background(const ofFloatColor & c){
941941
setBackgroundColor(c);
942942
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
943943
}
944944

945945
//----------------------------------------------------------
946946
void ofGLProgrammableRenderer::background(float brightness) {
947-
background(ofColor(brightness));
947+
background(ofFloatColor(brightness));
948948
}
949949

950950
//----------------------------------------------------------
951-
void ofGLProgrammableRenderer::background(int hexColor, float _a){
952-
background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a);
951+
void ofGLProgrammableRenderer::background(int hexColor, int _a){
952+
int r = (hexColor >> 16) & 0xff;
953+
int g = (hexColor >> 8) & 0xff;
954+
int b = (hexColor >> 0) & 0xff;
955+
background( (float)r/255.f, (float)g/255.f, (float)b/255.f, _a/255.f );
956+
// background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a);
953957
}
954958

955959
//----------------------------------------------------------
956-
void ofGLProgrammableRenderer::background(int r, int g, int b, int a){
957-
background(ofColor(r,g,b,a));
960+
void ofGLProgrammableRenderer::background(float r, float g, float b, float a){
961+
background(ofFloatColor(r,g,b,a));
958962
}
959963

960964
//----------------------------------------------------------
@@ -1562,7 +1566,7 @@ void ofGLProgrammableRenderer::uploadMatrices(){
15621566
//----------------------------------------------------------
15631567
void ofGLProgrammableRenderer::setDefaultUniforms(){
15641568
if(!currentShader) return;
1565-
currentShader->setUniform4f(COLOR_UNIFORM, currentStyle.color.r/255.,currentStyle.color.g/255.,currentStyle.color.b/255.,currentStyle.color.a/255.);
1569+
currentShader->setUniform4f(COLOR_UNIFORM, currentStyle.color.r,currentStyle.color.g,currentStyle.color.b,currentStyle.color.a);
15661570
bool usingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE);
15671571
currentShader->setUniform1f(USE_TEXTURE_UNIFORM,usingTexture);
15681572
currentShader->setUniform1f(USE_COLORS_UNIFORM,colorsEnabled);

libs/openFrameworks/gl/ofGLProgrammableRenderer.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,29 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
133133
void disableAntiAliasing();
134134

135135
// color options
136-
void setColor(int r, int g, int b); // 0-255
137-
void setColor(int r, int g, int b, int a); // 0-255
138-
void setColor(const ofColor & color);
139-
void setColor(const ofColor & color, int _a);
140-
void setColor(int gray); // new set a color as grayscale with one argument
136+
void setColor(float r, float g, float b); // 0-1
137+
void setColor(float r, float g, float b, float a); // 0-1
138+
void setColor(const ofFloatColor & color);
139+
void setColor(const ofFloatColor & color, float _a);
140+
void setColor(float gray); // new set a color as grayscale with one argument
141141
void setHexColor( int hexColor ); // hex, like web 0xFF0033;
142142

143143
void setBitmapTextMode(ofDrawBitmapMode mode);
144144

145145
// bg color
146-
ofColor getBackgroundColor();
147-
void setBackgroundColor(const ofColor & c);
148-
void background(const ofColor & c);
146+
ofFloatColor getBackgroundColor();
147+
void setBackgroundColor(const ofFloatColor & c);
148+
void background(const ofFloatColor & c);
149149
void background(float brightness);
150-
void background(int hexColor, float _a=255.0f);
151-
void background(int r, int g, int b, int a=255);
150+
void background(int hexColor, int _a=255);
151+
void background(float r, float g, float b, float a=1.f);
152152

153153
bool getBackgroundAuto();
154154
void setBackgroundAuto(bool bManual); // default is true
155155

156156
void clear();
157-
void clear(float r, float g, float b, float a=0);
158-
void clear(float brightness, float a=0);
157+
void clear(float r, float g, float b, float a=0.f);
158+
void clear(float brightness, float a=0.f);
159159
void clearAlpha();
160160

161161

@@ -217,7 +217,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
217217
void enableSeparateSpecularLight(){}
218218
void disableSeparateSpecularLight(){}
219219
void setSmoothLighting(bool b){}
220-
void setGlobalAmbientColor(const ofColor& c){}
220+
void setGlobalAmbientColor(const ofFloatColor& c){}
221221
void enableLight(int lightIndex);
222222
void disableLight(int lightIndex);
223223
void setLightSpotlightCutOff(int lightIndex, float spotCutOff){}

libs/openFrameworks/gl/ofGLRenderer.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void ofGLRenderer::draw(const ofPolyline & poly) const{
283283

284284
//----------------------------------------------------------
285285
void ofGLRenderer::draw(const ofPath & shape) const{
286-
ofColor prevColor;
286+
ofFloatColor prevColor;
287287
if(shape.getUseShapeColor()){
288288
prevColor = currentStyle.color;
289289
}
@@ -1045,19 +1045,19 @@ glm::mat4 ofGLRenderer::getCurrentNormalMatrix() const{
10451045
}
10461046

10471047
//----------------------------------------------------------
1048-
void ofGLRenderer::setColor(const ofColor & color){
1048+
void ofGLRenderer::setColor(const ofFloatColor & color){
10491049
setColor(color.r,color.g,color.b,color.a);
10501050
}
10511051

10521052
//----------------------------------------------------------
1053-
void ofGLRenderer::setColor(const ofColor & color, int _a){
1053+
void ofGLRenderer::setColor(const ofFloatColor & color, float _a){
10541054
setColor(color.r,color.g,color.b,_a);
10551055
}
10561056

10571057
//----------------------------------------------------------
1058-
void ofGLRenderer::setColor(int r, int g, int b){
1058+
void ofGLRenderer::setColor(float r, float g, float b){
10591059
currentStyle.color.set(r,g,b);
1060-
glColor4f(r/255.f,g/255.f,b/255.f,1.f);
1060+
glColor4f(r,g,b,1.f);
10611061
if(lightingEnabled && !materialBound){
10621062
#ifndef TARGET_OPENGLES
10631063
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
@@ -1068,9 +1068,9 @@ void ofGLRenderer::setColor(int r, int g, int b){
10681068

10691069

10701070
//----------------------------------------------------------
1071-
void ofGLRenderer::setColor(int r, int g, int b, int a){
1071+
void ofGLRenderer::setColor(float r, float g, float b, float a){
10721072
currentStyle.color.set(r,g,b,a);
1073-
glColor4f(r/255.f,g/255.f,b/255.f,a/255.f);
1073+
glColor4f(r,g,b,a);
10741074
if(lightingEnabled && !materialBound){
10751075
#ifndef TARGET_OPENGLES
10761076
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
@@ -1080,7 +1080,7 @@ void ofGLRenderer::setColor(int r, int g, int b, int a){
10801080
}
10811081

10821082
//----------------------------------------------------------
1083-
void ofGLRenderer::setColor(int gray){
1083+
void ofGLRenderer::setColor(float gray){
10841084
setColor(gray, gray, gray);
10851085
}
10861086

@@ -1089,7 +1089,7 @@ void ofGLRenderer::setHexColor(int hexColor){
10891089
int r = (hexColor >> 16) & 0xff;
10901090
int g = (hexColor >> 8) & 0xff;
10911091
int b = (hexColor >> 0) & 0xff;
1092-
setColor(r,g,b);
1092+
setColor((float)r/255.f,(float)g/255.f,(float)b/255.f);
10931093
}
10941094

10951095
//----------------------------------------------------------
@@ -1099,7 +1099,7 @@ void ofGLRenderer::clear(){
10991099

11001100
//----------------------------------------------------------
11011101
void ofGLRenderer::clear(float r, float g, float b, float a) {
1102-
glClearColor(r / 255., g / 255., b / 255., a / 255.);
1102+
glClearColor(r, g, b, a);
11031103
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
11041104
}
11051105

@@ -1127,35 +1127,38 @@ bool ofGLRenderer::getBackgroundAuto(){
11271127
}
11281128

11291129
//----------------------------------------------------------
1130-
ofColor ofGLRenderer::getBackgroundColor(){
1130+
ofFloatColor ofGLRenderer::getBackgroundColor(){
11311131
return currentStyle.bgColor;
11321132
}
11331133

11341134
//----------------------------------------------------------
1135-
void ofGLRenderer::setBackgroundColor(const ofColor & color){
1135+
void ofGLRenderer::setBackgroundColor(const ofFloatColor & color){
11361136
currentStyle.bgColor = color;
1137-
glClearColor(currentStyle.bgColor[0]/255.,currentStyle.bgColor[1]/255.,currentStyle.bgColor[2]/255., currentStyle.bgColor[3]/255.);
1137+
glClearColor(currentStyle.bgColor[0],currentStyle.bgColor[1],currentStyle.bgColor[2], currentStyle.bgColor[3]);
11381138
}
11391139

11401140
//----------------------------------------------------------
1141-
void ofGLRenderer::background(const ofColor & c){
1141+
void ofGLRenderer::background(const ofFloatColor & c){
11421142
setBackgroundColor(c);
11431143
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
11441144
}
11451145

11461146
//----------------------------------------------------------
11471147
void ofGLRenderer::background(float brightness) {
1148-
background(ofColor(brightness));
1148+
background(ofFloatColor(brightness));
11491149
}
11501150

11511151
//----------------------------------------------------------
1152-
void ofGLRenderer::background(int hexColor, float _a){
1153-
background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a);
1152+
void ofGLRenderer::background(int hexColor, int _a){
1153+
int r = (hexColor >> 16) & 0xff;
1154+
int g = (hexColor >> 8) & 0xff;
1155+
int b = (hexColor >> 0) & 0xff;
1156+
background ( (float)r/255.f, (float)g/255.f, (float)b/255.f, _a/255.f);
11541157
}
11551158

11561159
//----------------------------------------------------------
1157-
void ofGLRenderer::background(int r, int g, int b, int a){
1158-
background(ofColor(r,g,b,a));
1160+
void ofGLRenderer::background(float r, float g, float b, float a){
1161+
background(ofFloatColor(r,g,b,a));
11591162
}
11601163

11611164
//----------------------------------------------------------
@@ -1818,8 +1821,8 @@ void ofGLRenderer::setSmoothLighting(bool b){
18181821
}
18191822

18201823
//----------------------------------------------------------
1821-
void ofGLRenderer::setGlobalAmbientColor(const ofColor& c){
1822-
GLfloat cc[] = {c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f};
1824+
void ofGLRenderer::setGlobalAmbientColor(const ofFloatColor& c){
1825+
GLfloat cc[] = {c.r, c.g, c.b, c.a};
18231826
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, cc);
18241827
}
18251828

libs/openFrameworks/gl/ofGLRenderer.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,22 @@ class ofGLRenderer: public ofBaseGLRenderer{
120120
void disableAntiAliasing();
121121

122122
// color options
123-
void setColor(int r, int g, int b); // 0-255
124-
void setColor(int r, int g, int b, int a); // 0-255
125-
void setColor(const ofColor & color);
126-
void setColor(const ofColor & color, int _a);
127-
void setColor(int gray); // new set a color as grayscale with one argument
123+
void setColor(float r, float g, float b); // 0-1
124+
void setColor(float r, float g, float b, float a); // 0-1
125+
void setColor(const ofFloatColor & color);
126+
void setColor(const ofFloatColor & color, float _a);
127+
void setColor(float gray); // new set a color as grayscale with one argument
128128
void setHexColor( int hexColor ); // hex, like web 0xFF0033;
129129

130130
void setBitmapTextMode(ofDrawBitmapMode mode);
131131

132132
// bg color
133-
ofColor getBackgroundColor();
134-
void setBackgroundColor(const ofColor & c);
135-
void background(const ofColor & c);
133+
ofFloatColor getBackgroundColor();
134+
void setBackgroundColor(const ofFloatColor & c);
135+
void background(const ofFloatColor & c);
136136
void background(float brightness);
137-
void background(int hexColor, float _a=255.0f);
138-
void background(int r, int g, int b, int a=255);
137+
void background(int hexColor, int _a=255);
138+
void background(float r, float g, float b, float a=1.f);
139139

140140
void setBackgroundAuto(bool bManual); // default is true
141141
bool getBackgroundAuto();
@@ -176,7 +176,7 @@ class ofGLRenderer: public ofBaseGLRenderer{
176176
void disableSeparateSpecularLight();
177177
bool getLightingEnabled();
178178
void setSmoothLighting(bool b);
179-
void setGlobalAmbientColor(const ofColor& c);
179+
void setGlobalAmbientColor(const ofFloatColor& c);
180180

181181
// lighting per light
182182
void enableLight(int lightIndex);

0 commit comments

Comments
 (0)