help in building a color lookup table
-
hello, i'm new to openGL, and i'm trying to build a color lookup table of size 265 is there any thing wrong in my code??:confused::confused: // i define the array in header GLfloat color_table[256][4]; void BuildColorLookUpTable() { for(INT i = 0; i < 256; i++) { GLfloat red=i/255; GLfloat green=0; GLfloat blue=1-i/255; color_table[i][0] = 0; color_table[i][0] = red; color_table[i][0] = green; color_table[i][0] = blue; glutSetColor(i, red, green, blue); } } also, can anyone pls give me some guides :doh: thanks:rose:
-
hello, i'm new to openGL, and i'm trying to build a color lookup table of size 265 is there any thing wrong in my code??:confused::confused: // i define the array in header GLfloat color_table[256][4]; void BuildColorLookUpTable() { for(INT i = 0; i < 256; i++) { GLfloat red=i/255; GLfloat green=0; GLfloat blue=1-i/255; color_table[i][0] = 0; color_table[i][0] = red; color_table[i][0] = green; color_table[i][0] = blue; glutSetColor(i, red, green, blue); } } also, can anyone pls give me some guides :doh: thanks:rose:
-
-
i used i/255 to compute the red value,i didn't test my program yet but my question was is this enough to build the lookup table or I should use some gl commands to enable the index color mode?? can i use now glindex()?? thanks
I never used Glut when I was playing with OpenGL but it appears like if you're in color index mode that should setup the table. There might even be a default table already there. I'm not sure why you're maintaining the array of colors, when you can access Glut's color table once you've set it. You're trying to setup up the table with green a constant zero. Red varying linearly from zero to one and blue being one minus red. However, the reason I asked you to think about what i/255 evaluates to means that's not what you're going to get. Your color table will be considerably more boring.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!! -
I never used Glut when I was playing with OpenGL but it appears like if you're in color index mode that should setup the table. There might even be a default table already there. I'm not sure why you're maintaining the array of colors, when you can access Glut's color table once you've set it. You're trying to setup up the table with green a constant zero. Red varying linearly from zero to one and blue being one minus red. However, the reason I asked you to think about what i/255 evaluates to means that's not what you're going to get. Your color table will be considerably more boring.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!!thanks, i solved the problem of th table but i have another question pls i implement this function to render the face normal of the mesh but when i debug i found that the program doesn't enter the loop at all and i get this in the watch of the debug when i type i: i CXX0017: Error: symbol "i" not found inline void CMesh::RenderFaceNormals() { float t=0.5; CVector v0,v1; for(int i=0 ; iget_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3; v1 = t * faces[i]->get_normal(); glBegin(GL_LINES); glVertex3f(v0.X(), v0.Y(), v0.Z()); // origin of the line glVertex3f(v1.X(), v1.Y(), v1.Z()); // ending point of the line glEnd(); } } it seems that my program doesn't see i?? can anyone help me?? :((
-
thanks, i solved the problem of th table but i have another question pls i implement this function to render the face normal of the mesh but when i debug i found that the program doesn't enter the loop at all and i get this in the watch of the debug when i type i: i CXX0017: Error: symbol "i" not found inline void CMesh::RenderFaceNormals() { float t=0.5; CVector v0,v1; for(int i=0 ; iget_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3; v1 = t * faces[i]->get_normal(); glBegin(GL_LINES); glVertex3f(v0.X(), v0.Y(), v0.Z()); // origin of the line glVertex3f(v1.X(), v1.Y(), v1.Z()); // ending point of the line glEnd(); } } it seems that my program doesn't see i?? can anyone help me?? :((
As written above, I'm not sure how this compiled. Your for loop is malformed by missing the closing parenthesis at the very least and the second semicolon.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!! -
As written above, I'm not sure how this compiled. Your for loop is malformed by missing the closing parenthesis at the very least and the second semicolon.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!!No i'm sure there is no syntax errors, the error in the loop header only appear when i copy from my program anyone have solutions for my problem????
inline void CMesh::RenderFaceNormals() { float t=0.5; CVector v0,v1; for(int i=0 ; i< get_numOfFaces() ;i++) { v0 = (verts[faces[i]->get_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3; v1 = t * faces[i]->get_normal(); glBegin(GL_LINES); glVertex3f(v0.X(), v0.Y(), v0.Z()); // origin of the line glVertex3f(v1.X(), v1.Y(), v1.Z()); // ending point of the line glEnd(); } }
-
No i'm sure there is no syntax errors, the error in the loop header only appear when i copy from my program anyone have solutions for my problem????
inline void CMesh::RenderFaceNormals() { float t=0.5; CVector v0,v1; for(int i=0 ; i< get_numOfFaces() ;i++) { v0 = (verts[faces[i]->get_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3; v1 = t * faces[i]->get_normal(); glBegin(GL_LINES); glVertex3f(v0.X(), v0.Y(), v0.Z()); // origin of the line glVertex3f(v1.X(), v1.Y(), v1.Z()); // ending point of the line glEnd(); } }
-
-
Then it should be ok with defining the loop variable inside the for header. But to determine if something else is causing a side effect, try this: int i; for (i = 0 ; whatever your condition was ; i++) { your stuff }
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!! -
Then it should be ok with defining the loop variable inside the for header. But to determine if something else is causing a side effect, try this: int i; for (i = 0 ; whatever your condition was ; i++) { your stuff }
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!! -
Thanks Tim very much for ur help i solve the problem, the problem was that my project was in release mode so i changed it now to debuge mode and it works well i really appreciate your help:rose:
I'm not sure how switching to debug compile from release "fixes" the problem. Usually then that happens, you have a problem with unitialized memory that debug mode automatically sets to zero or you're using something like an assert macro that is compiled out in release mode and leaves a hole in your code but lets debug mode work.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke
I'm a proud denizen of the Real Soapbox[^]
ACCEPT NO SUBSTITUTES!!! -
Thanks Tim very much for ur help i solve the problem, the problem was that my project was in release mode so i changed it now to debuge mode and it works well i really appreciate your help:rose:
Hi, if the release build also works well, then you can claim you solved the problem. if not, you just closed your eyes. switching to debug mode does not solve anything that turning off the computer would not solve. if you need some advice on fixing release problems, read Debugging Release Mode Problems[^] and this[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.