Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: using macros in a GLUT function

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    May 2002
    Location
    Cologne, Germany
    Posts
    4

    using macros in a GLUT function

    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
    Please be patiant...
    I'm pretty new to OpenGL

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2002
    Location
    York, UK
    Posts
    128

    Re: using macros in a GLUT function

    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2002
    Location
    Cologne, Germany
    Posts
    4

    Re: using macros in a GLUT function

    Thanx for that... I'll have to try it!

    Moritz

    [This message has been edited by Moritz (edited 05-25-2002).]
    Please be patiant...
    I'm pretty new to OpenGL

  4. #4
    Junior Member Newbie
    Join Date
    May 2002
    Location
    Cologne, Germany
    Posts
    4

    Re: using macros in a GLUT function

    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:
    Code :
    #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
    Please be patiant...
    I'm pretty new to OpenGL

  5. #5
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: using macros in a GLUT function

    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
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •