Archived

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

ezekio

how to write a scroller

Recommended Posts

Hy all you opengl programmers... I have a problem for sometime now : i want to write a scroller but don't quite know how, this is what a managed to do so far : //declarations float x,y; int i; char* text[10]; int InitGL(GLvoid) { //...init stuff x = 30; y = 469; i = 0; text[0] = "Scrolling text"; text[1] = "bla bla"; text[2] = "bla bla again" } int DrawGLScene(GLvoid) { //draw stuff glScissor(2, 2, 780, 580); glEnable(GL_SCISSOR_TEST); glColor4f(1.0,1.0,1.0,1.0); glPrint(((int) x),((int)y),0,((const char* )text)); glDisable(GL_SCISSOR_TEST); y-=0.1; i++; glFlush(); } If i use glPrint(((int) x),((int)y),0,((const char* )text[0])); it works showing one single line scrolling up the screen, but if i try to make a loop (like in the example above) so that all the 3 lines scroll together one after the other the program crashes... Any ideas on how to make it work ? Edited by - ezekio on November 18, 2001 1:38:48 PM

Share this post


Link to post
Share on other sites
hmm what is up with this line:
glPrint(((int) x),((int)y),0,((const char* )text));

?
first of all, if I understand what you're doing right, shouldn't it be text?

also I don't understand how you're doing the integer casting. The way I do it is int(x) not (int) x

unless there is something different about how your compiler does casting, but then it wouldn't be ansi C I suppose.


hmmm I see the i in brackets won't show up

i meant:
    
text[i]


oh and if you want to display source code the code for it is
[ source ]
.... your code here...
[ / source ]

without the spaces


Edited by - element2001 on November 18, 2001 2:39:53 PM

Share this post


Link to post
Share on other sites
(int) x is the good old fashioned c-style cast. int(x) is the "functional cast" notation that was brought in for the early drafts of the c++ standard (which does the same thing as the old cast).

Officially, both types have been replaced by the new c++ casts:

  static_cast<int>
reinterpret_cast<int>
const_cast<int>
dynamic_cast<int>


You`ll still see old c hacks like myself using the classic cast notation every now and then (even though its been depreciated). They are more concise, but easy to misuse.

EDITL Forgot the source tags...

Edited by - Krunk on November 18, 2001 2:46:50 PM

Share this post


Link to post
Share on other sites
Wow, this doesn''t make sense to me at all. How did you get this to compile?


1. How exactly are you assigning text into the CHAR POINTER ARRAY. It''s a char pointer, not a buffer. You need a buffer...

-nt20


"nikolatesla20"

Share this post


Link to post
Share on other sites
Yes, that and also when you increment i++ wouldn''t it go above 10 which would put it past the last element in the array? assuming you had the assignments of text right which they aren''t either as NikolaTesla pointed out.

Share this post


Link to post
Share on other sites
well first of all the code works
second this is how i declared the function glPrint
    
GLvoid glPrint(GLint x, GLint y, int set, const char *fmt, ...)

So if i try to use the function like this glprint(x,y,0,text);
it wont work 'cause i have x,y float type and the text[i] is an array and ' ftm ' is a pointer so i have to transform the variables in integer and const char* just like in the declaration
element2001 i have a wrote a code that ends the scroller if i>2 so that isn't a problem, i just haven't posted it here 'cause it's not relevant
You are right the corect code is

glPrint(((int) x),((int)y),0,((const char* )text[i]));

I was using code & /code from another forum

Anyway besides my bad english (sorry) i still don't have a good method to scroll some texts . Any ideeas ?

To be more specific i'm trying to do something like the end scroller from the fr8-08 demo ...

Edited by - ezekio on November 19, 2001 7:01:48 AM

Share this post


Link to post
Share on other sites
nikolatesla20:

A string is an array of char.
Arrays and pointers are interchangeable (except for memory management issues )
A static chain (one you have in your code) can be assigned to a char* without any problems... so long as you don't try to modify the string itself.

edit:
And a buffer is a space in memory... in this case, represented by a pointer to char, that is, a char array.

Edited by - Fruny on November 19, 2001 7:22:14 AM

Share this post


Link to post
Share on other sites