#### Archived

This topic is now archived and is closed to further replies.

# Custom Print Function (HELP!)

This topic is 5911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I need some help figuring out what''s wrong with this code that I''ve been toying with for a couple hours now.

BOOL glPrintf (float x, float y, GLubyte r, GLubyte g, GLubyte b, int style, char* text, ...)
{
if (text == 0) return false;
va_list arglist;
float *array = 0;
char buff[256];
va_start (arglist, text);
vsprintf (buff, text, arglist);
va_end (arglist);
array = new float[strlen(buff)*20];		//can this be done?

if (!array) return FALSE;
int loop;
float actualx, actualy, subx, suby;		//actual is for the vertex positions and sub is for texcoords

actualx = x;
actualy = y;
for (loop = 0; loop < strlen(buff); loop++) {
subx = float((buff[loop]-32)%16)/16.0f;
suby = float((buff[loop]-32)/16.0f)/8.0f;
array[loop*20+0] = subx; array[loop*20+1] = 1-suby-0.125; array[loop*20+2] = actualx; array[loop*20+3] = actualy-0.5; array[loop*20+4] = 0.0f;		//BL

array[loop*20+5] = subx+0.0625; array[loop*20+6] = 1-suby-0.125; array[loop*20+7] = actualx+0.5; array[loop*20+8] = actualy-0.5; array[loop*20+9] = 0.0f;	//BR

array[loop*20+10] = subx+0.0625; array[loop*20+11] = 1-suby; array[loop*20+12] = actualx+0.5; array[loop*20+13] = actualy; array[loop*20+14] = 0.0f;	//TR

array[loop*20+15] = subx; array[loop*20+16] = 1-suby; array[loop*20+17] = actualx; array[loop*20+18] = actualy; array[loop*20+19] = 0.0f;			//TL

actualx += 0.5f;
}
glPushMatrix();

glPushAttrib (GL_COLOR_BUFFER_BIT);
glColor3ub (r, g, b);
glBindTexture (GL_TEXTURE_2D, texture[2].texID);
glInterleavedArrays (GL_T2F_V3F, 0, array);
glPopAttrib();
glPopMatrix();
delete [] array;
array = 0;
return TRUE;
}

As far as I can see everything has been declared properly and the array contains the right data. (I think ) In the most recent build, when this function runs I get the 10H exception. With previous debuging episodes I''m pretty sure that means a division by zero, but I''m not dividing by anything!!! Also, when I can get it to work without complaining it seems to dump a random texture onto the "letters" (i.e. it doesn''t look like any manipulation of the font texture I''m using) This is frustrating! If anyone can help, I will be deeply grateful. Thanks in advance. _____________________________ And the Phoenix shall rise from the ashes... --Thunder_Hawk -- ¦þ ______________________________

##### Share on other sites
I''ve been trying to fix this thing by simplifying it, but this is about as far as it can go (I could remove the color parameters, but they shouldn''t have anything to do with the problem ).

  BOOL glPrint (float x, float y, GLubyte r, GLubyte g, GLubyte b, int style, char* text){	if (text == 0) return false;	float *array = 0;	array = new float[strlen(text)*20];		//can this be done?	if (!array) return FALSE;	int loop;	float actualx, actualy, subx, suby;		//actual is for the vertex positions and sub is for texcoords	actualx = x;	actualy = y;	for (loop = 0; loop < strlen(text); loop++) {		subx = float((*(text+loop)-32)%16)/16.0f;		suby = float((*(text+loop)-32)/16.0f)/8.0f;		array[loop*20+0] = subx; array[loop*20+1] = 1-suby-0.125; array[loop*20+2] = actualx; array[loop*20+3] = actualy-0.5; array[loop*20+4] = 0.0f;		//BL		array[loop*20+5] = subx+0.0625; array[loop*20+6] = 1-suby-0.125; array[loop*20+7] = actualx+0.5; array[loop*20+8] = actualy-0.5; array[loop*20+9] = 0.0f;	//BR		array[loop*20+10] = subx+0.0625; array[loop*20+11] = 1-suby; array[loop*20+12] = actualx+0.5; array[loop*20+13] = actualy; array[loop*20+14] = 0.0f;	//TR		array[loop*20+15] = subx; array[loop*20+16] = 1-suby; array[loop*20+17] = actualx; array[loop*20+18] = actualy; array[loop*20+19] = 0.0f;			//TL		actualx += 0.5f;	}	glPushMatrix();//	glLoadIdentity();	glPushAttrib (GL_COLOR_BUFFER_BIT);	glColor3ub (r, g, b);	glBindTexture (GL_TEXTURE_2D, texture[2].texID);	glInterleavedArrays (GL_T2F_V3F, 0, array);	glDrawArrays (GL_QUADS, 0, strlen(text)*20);	glPopAttrib();	glPopMatrix();	delete [] array;	array = 0;	return TRUE;}

I ventured out on a limb when I originally wrote this code, and now I need someone to show me the strongest branch.

I''m not entirely sure if that line with the new statement is valid.

Ahhhhhhhhhhhh, FEEEEEEEEED MEEEEEE.....whoops.....HEEEELLLLLLP MEEEEEE!

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

##### Share on other sites
I guess everyone is as stumped about this as I am. I''ve figured out that when I coment out the draw arrays line I have no error, but that tells me absolutely nothing about why this doesn''t work. If anyone even has the most remote idea about this problem I''d love to hear it.

##### Share on other sites
Can someone at least point me in the right direction. I mean someone has to have used Interleaved Arrays in a dynamic situation, Right. Hell, at this point I''d settle on a "hello" just to know someone read this thread. I''d like to use vertex pointers to dynamicly print stuff if you can''t tell.

##### Share on other sites
Come on, I asked an intelligent question and on a great board and got nothing...no thought provoking questions, no hints at an answer, no childish mocking, no nothing. Maybe I should move this to a different forum, but where...Oh well, I guess I''ll have to forget about this function all together...Goodbye

##### Share on other sites
sheeesh! you ask the question 2h before that last reply, not everyone trolls the boards 24/7 ya know, sometimes ya have to wait for replies, if you not prepared to wait then I surgest you do take your childish ''no one will help me'' pouting else where

##### Share on other sites
Wow even the guilt approach doesn't work on you guys. Seriously, though, I can't figure out what's going wrong. I flat out need help. Answering any of these questions would help:

1) What are all of the general reasons for a 10H exception (fatal error)?
2) Does anyone have working code using glInterleavedArrays()?
3) Can a new statement have a dynamic number in the brackets []?
5) How much wood could a woodchuck chuck if a woodchuck could chuck wood?
6) Am I crazy, or have I just lost my mind?
7) Why is it that only time can tell what the future brings (that's a paradox)?
8) Why don't I use the word *bump* when I am trying to bump my question?
9) Why did I try the guilt trip technique on a programming board (makes no sense)?
10) How many fingers am I holding up?
11) Why do I feel that I should have more questions?

[edited by - Thunder_Hawk on July 17, 2002 8:16:48 PM]

[edited by - Thunder_Hawk on July 17, 2002 8:18:53 PM]

##### Share on other sites
run it through a debugger.

1) To tell you you/the computer did something wrong.
2) Not me.
3) Yes.
4) Probably.
5) Dunno.
6) I'd say a little bit of both.
7) Because we live in a 3D universe where we can't move along the time axis(which doesnt exist) freely.
8) Because you like typing alot.
9) To quote: Makes no sense.
10) None, they're all on your keyboard.
11) You shouldn't have more questions, so it's probably because your weird.

Eric

[edited by - ERJO on July 17, 2002 8:31:47 PM]

##### Share on other sites
I tried looking at you code, but I''m afraid that it''s way out of my depth. I couldn''t make sense of much of it...

But just to add a little constructive context to this post, I think your new[strlen(buff)*20] expression is OK, at least. But alternatively you could try replacing it with a malloc() call.

##### Share on other sites
quote:
Original post by nicba
I tried looking at you code, but I''m afraid that it''s way out of my depth. I couldn''t make sense of much of it...

But just to add a little constructive context to this post, I think your new[strlen(buff)*20] expression is OK, at least. But alternatively you could try replacing it with a malloc() call.

Thanks for that,I''ve really been wanting to rule that out. Actually the only reason I wanted to use "new" was to avoid the sizeof() "function" and improve portability (which should really be the least of my concerns).

By the way Eric, I was looking for more jokish answers to those questions and I''ve yet to understand (at even the simplest level) turbo debugger. I use the free Borland command line tools as I have little \$ to spare.

To help in the understanding of that code, I wrote it based on the NeHe font tutorials and my will to find a good use for vertex pointers.

If I''m lucky, my newest idea might be the big break. ¦þ

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
13

• 9
• 9
• 25
• 16
• 9
• ### Forum Statistics

• Total Topics
632610
• Total Posts
3007406

×