character sets

Started by
12 comments, last by kburkhart84 18 years, 6 months ago
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
Advertisement
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.
Currently, in my really ugly text-implementation I do like this:
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
sorry of my comments there was a typo error :- it should read please think simple.

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.
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.
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.
well i think i understand your tip, but note that in the rendering stage 3 colors are already specified like :-
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

This topic is closed to new replies.

Advertisement