iDevGames Forums
Can someone write me a simple GLUT example? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Can someone write me a simple GLUT example? (/thread-6899.html)



Can someone write me a simple GLUT example? - Joseph Duchesne - Jul 20, 2003 07:50 AM

Could someone please write a simple example ware there is a green square in the middle of the screen. If you press one of the A,D,S and W keys it moves left right up or down?

I tried to write my own program but for some strange reason glutmainloop wouldn't work so I stuck it somewhare else and now the block only moves when I am moveing or resizing the window Grin .

Anyone?


Can someone write me a simple GLUT example? - Jake - Jul 20, 2003 08:40 AM

I can write you one in cocoa, but you are using Carbon right?


Can someone write me a simple GLUT example? - Joseph Duchesne - Jul 20, 2003 10:44 AM

I use either. It doesn't matter. Thanks.


Can someone write me a simple GLUT example? - Jake - Jul 20, 2003 11:26 AM

Ok I am just modifying tutorial 2 from NeHe because I don't feel like typing everything to set up GL again, I will email it to you in a sec.


Can someone write me a simple GLUT example? - OneSadCookie - Jul 20, 2003 02:14 PM

I already posted one... but here goes again...

Code:
#include <stdlib.h>

#if defined(__APPLE_CC__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // your drawing code goes here

    glutSwapBuffers();
}

void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);

    (void)glutCreateWindow("GLUT Program");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);

    glutMainLoop();

    return EXIT_SUCCESS;
}