🔒 Locked
character sets
Advertisement
Original Post
I need to display more than 1 set of text characters in various colors. But currently do not know of a way to do so. Currently I'd only one character set that is 128 ASCII. When any of similar characters are rendered to a new color, the previous one is affected therefore i thought maybe by creating more than one set is the correct approach. please advise on how to achieve that or provide alternative solutions. as illustration:- "aaa" first "a" red, second "a" yellow, third "a" green. I used the following line to display the characters. glCallList(gluiBase + char) but not able to get those "aaa" in 3colors. thanks daniel
The description you've given seems too vague. Can you post some code snippets that express how you are doing the rendering, and how you are defining the CallList exemplarily?
In fact, it is absolutely possible to render different glyphs (as an implementation of shapes) in different colors. It would become more difficult if the glyphs are given by textures, of course.
In fact, it is absolutely possible to render different glyphs (as an implementation of shapes) in different colors. It would become more difficult if the glyphs are given by textures, of course.
Currently, in my really ugly text-implementation I do like this:
It's a bit ugly(=and possible slow, since it is intermediate), but I could rather easily add suport for different colored textsubstrings by issuing a glColor4f in Character::print instead of Font::print()
void Font::print(float p_x, float p_y, float r, float g, float b, const std::string& p_str) { const char* str = p_str.c_str(); const int length = p_str.length(); const float p_alpha = 1.0f; int i=0; float x = p_x; float y = p_y; glColor4f(r, g, b, p_alpha); glBindTexture(GL_TEXTURE_2D, m_characterMap.getId()); for(i=0; i<length; ++i) { at(str).print(x, y); }}void Character::print(float &x, float &y) { const float scale = 0.8f; const float width = w * 10.0f * scale; const float height = 0.5f * scale; const float ax = x; const float ay = y; const float bx = ax+width; const float by = ay+height; verify(); glBegin(GL_QUADS); glTexCoord2f(u, v); glVertex3f(ax, by, 0); glTexCoord2f(u+w, v); glVertex3f(bx, by, 0); glTexCoord2f(u+w, h+v); glVertex3f(bx, ay, 0); glTexCoord2f(u, h+v); glVertex3f(ax, ay, 0); glEnd(); verify(); x+= width;}It's a bit ugly(=and possible slow, since it is intermediate), but I could rather easily add suport for different colored textsubstrings by issuing a glColor4f in Character::print instead of Font::print()
It looks like you are doing fonts from a texture, which should be fine. If you have the texture set up with GL_MODULATE, you could just change color using glColor3f() between printing each letter. The color of textures are modified when you change the color.
what i was with characater set is basically a 3d object and it resembles alphabetical characters and not texture objects. Take it as one of the 26 characters. The color for any one of them presented no issue But only for applying different color to a same character like what were described earlier. For example A, A, & A. if all the "A"s is the same color no problem but only if I want them to be different. Though I'd repeated my explaination here please bear wih me and you must not think simple of what is to be done.
ciao
ciao
sorry of my comments there was a typo error :- it should read please think simple.
ciao
ciao
Ok. You have code to render an A as a shape. It consist of possibly several pairs of glBegin/glEnd, each one w/ vertex pushing inbetween. There should be _no_ glColor.
Now make another routine that sets the color to red, then invoke the A drawing routine, then translate by the width of the shape of A, then set the color to green, then invoke the A drawing routine a second time.
If these steps result in a red A and a green A (what _should_ happen ;-) then there is possibly a problem w/ the definition of your CallLists. But, if also these simple steps fail, then I see no way other than that you post snippets of your code.
Now make another routine that sets the color to red, then invoke the A drawing routine, then translate by the width of the shape of A, then set the color to green, then invoke the A drawing routine a second time.
If these steps result in a red A and a green A (what _should_ happen ;-) then there is possibly a problem w/ the definition of your CallLists. But, if also these simple steps fail, then I see no way other than that you post snippets of your code.
my code works in 2 phase:-
[1] prepare
[2] draw
nb:- gluiBase1 = glListBase(128);
in the stage [1], the char is render with color as follows:-
prepareChar(GLuint gluiBase, char c, int iClr){
load3ds(c);
glBegin();
glNewList(gluiBase + c);
render_vertex3f_with_color_i(iClr);
glEndList();
glEnd();
}
[2] it is then drawn as follows:-
drawChar(GLuint gluiBase, char c){
glBegin();
glCallList(gluiBase + c);
glEnd();
}
the above summarised in simplified form and thus can be seen if the same char is used but with different iClr, definitely the previous one will be overwritten.Thus maybe another char set will help like the following:-
gluiBase1 = glListBase(128); and
gluiBase2 = glListBase(128); and
then pass one of those to the above routines, but those did not seemed to worked.
please advise.
daniel lee.
[1] prepare
[2] draw
nb:- gluiBase1 = glListBase(128);
in the stage [1], the char is render with color as follows:-
prepareChar(GLuint gluiBase, char c, int iClr){
load3ds(c);
glBegin();
glNewList(gluiBase + c);
render_vertex3f_with_color_i(iClr);
glEndList();
glEnd();
}
[2] it is then drawn as follows:-
drawChar(GLuint gluiBase, char c){
glBegin();
glCallList(gluiBase + c);
glEnd();
}
the above summarised in simplified form and thus can be seen if the same char is used but with different iClr, definitely the previous one will be overwritten.Thus maybe another char set will help like the following:-
gluiBase1 = glListBase(128); and
gluiBase2 = glListBase(128); and
then pass one of those to the above routines, but those did not seemed to worked.
please advise.
daniel lee.
If I interpret your code right, then you have a fixed base to the call lists, and use the charater's ASCII code as index. So, an A gives the same index as an, uhm, A, regardless whether the first one should be red and the seconds one green, right? So the same CallList is called on each one A!
I came back to the essence of my previous posting: _Don't_ set the color of the shapes already during preparing the call lists. _Instead_ set it each time before calling the CallList! (I mean especially what you've named "render_vertex3f_with_color_i(iClr);"!)
P.S.: Please set code snippets into [ source ] ... [ /source ] brackets (but without the spaces). It normally helps reading the posting.
I came back to the essence of my previous posting: _Don't_ set the color of the shapes already during preparing the call lists. _Instead_ set it each time before calling the CallList! (I mean especially what you've named "render_vertex3f_with_color_i(iClr);"!)
P.S.: Please set code snippets into [ source ] ... [ /source ] brackets (but without the spaces). It normally helps reading the posting.
well i think i understand your tip, but note that in the rendering stage 3 colors are already specified like :-
hence i need to find an alternative method to draw those colored-objects
ciao
glBegin(GL_TRIANGLES); glColor3f(1.0, 1.0, 1.0); glVertex3f( obj.vertex[ obj.polygon[l_index].a ].X, obj.vertex[ obj.polygon[l_index].a ].Y, obj.vertex[ obj.polygon[l_index].a ].Z); glColor3f(0.0, 1.0, 0.0); glVertex3f( obj.vertex[ obj.polygon[l_index].b ].X, obj.vertex[ obj.polygon[l_index].b ].Y, obj.vertex[ obj.polygon[l_index].b ].Z); ///----------------- THIRD VERTEX ----------------- glColor3f(0.0, 1.0, 0.0); glVertex3f( obj.vertex[ obj.polygon[l_index].c ].X, obj.vertex[ obj.polygon[l_index].c ].Y, obj.vertex[ obj.polygon[l_index].c ].Z);glEnd();hence i need to find an alternative method to draw those colored-objects
ciao
I see that colors are set there (to be exact, one color is repeatly set!), but there is no need to do so. To be precise: _It is the problem!_ glColor could be set also outside glBegin/glEnd pairs, and their setting is current as long as not being overwritten. Since all of your geometry of a single shape should be rendered in one color, there is no need (from this point of view) to set the color there. As I know, a CallList does not store the color by itself. So, if you have your fingers on what you've called the "rendering stage 3", why do you not want to remove settings of color there and follow my tip? Well, I think this is the solution of your problem. It's up to you to probe it or not.
[Edited by - haegarr on October 27, 2005 9:49:02 AM]
[Edited by - haegarr on October 27, 2005 9:49:02 AM]
my concept of drawing the alphabets is to have it color better looking than just one flat color just why the use of 3 color specification in the rendering section. so for that if I use only one color specification and then callList it will draw the alphabet with one solid color which is not what the original intention was. So is there some way to that just that.
ciao.
ciao.
I now realized the first time that your intention is a multi-colored character shape _and_ a multi-colored text on character basis. Well, if color alterations inside a single shape should go furthur than brigthness (say, they also alter the hue, and your code snippet suggests so) and you still want to use CallList, then I don't see another way than using different CallLists. If you properly allocate different lists (see docs for glGenLists and glNewList) and prepare them as usual, I don't see why it should not work. For OpenGL it makes no difference whether you allocate 26 lists each one for a single character or else a bunch of 26 lists at once, and so it makes no difference if you allocate 2 times a bunch of 26 lists.
However, I now think whether call lists are the right solution for you. It depends on how many differently colored alphabets you want, and how big your alphabets may get. Using texture fonts is more efficient than shape fonts, but of course they are flat and may suffer from scaling. If, on the other hand, your font is used, say, for a screen saver showing a rotating text (as a very basic example) then you need shapes but you could drop call lists and render the shapes directly.
However, I now think whether call lists are the right solution for you. It depends on how many differently colored alphabets you want, and how big your alphabets may get. Using texture fonts is more efficient than shape fonts, but of course they are flat and may suffer from scaling. If, on the other hand, your font is used, say, for a screen saver showing a rotating text (as a very basic example) then you need shapes but you could drop call lists and render the shapes directly.
If you are using wglUseFontBitmaps() or wglUseFontOutlines() to actually crate the Display lists, you could just change the color and the color affects the list since there is no color change within the list.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement