PDA

View Full Version : using macros in a GLUT function



Moritz
05-23-2002, 07:27 AM
Hello everyone!

I got a question:
I want to use a macro in a GLUT function, i.a.:
#define CURRENT_DATE (23. May 2002)
and want to use it within the glutCreateWindow();
How to use it? My compiler won't allow me
glutCreateWindow("Current date is: "CURRENT_DATE);
I can't find any information about it...

please help me!

Moritz

Rob Fletcher
05-24-2002, 06:15 AM
Howsabout ...

#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
time_t t;
char *c;
int w;
t = time(NULL);
c = (char*)malloc(45*sizeof(char));
sprintf(c, "Current date is: %s",asctime(localtime(&t)));
w = glutCreateWindow(c);
}


Rob.

Moritz
05-24-2002, 11:45 PM
Thanx for that... I'll have to try it! http://www.opengl.org/discussion_boards/ubb/smile.gif

Moritz

[This message has been edited by Moritz (edited 05-25-2002).]

Moritz
05-25-2002, 02:06 AM
Hmm... the idea is good, but my realisation isn't that "efficiant".
May you could help me again. (BTW: I don't need the date of compilation, I just need the date of the source release.)

So here's my source:



#include <stdio.h>
#include <string.h>
#include <gl/glut.h>

#define BUILD "0001"
#define BUILD_DATE "23.05.2002"

void main(void)
{
char window_name[45]
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

strcpy (window_name, "Project One - Build: ");
strcat (window_name, BUILD);
strcat (window_name, " [");
strcat (window_name, BUILD_DATE);
strcat (window_name, "]");

glutCreateWindow(window_name);
//...
//...
}

Is there any way to use C++ instead of C? Any faster way?
BTW: It currently works! My window name is "Project one - Build 0001 [23.05.2002]

But it looks quit unefficiant :-(

Moritz

jmathies
05-25-2002, 11:10 AM
If your using mfc you can use CString:

CString str;
str = "Project One - Build: ";
str += BUILD;
str += BUILD_DATE;

there are other ways. but you basically have
it right. I'd suggest bumping the char array
up to 100 bytes or so so you never overwrite it.

regards,
Jim