Can someone write me a simple GLUT example?

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
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?
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #2
I can write you one in cocoa, but you are using Carbon right?
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #3
I use either. It doesn't matter. Thanks.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #4
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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;
}
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL to write to a browser pane ???? Mark Whittemore 2 2,634 Sep 22, 2005 08:35 AM
Last Post: TomorrowPlusX
  PBuffer &amp; Render to Texture (read &amp; write) habicht 4 3,992 Feb 7, 2005 05:33 PM
Last Post: habicht
  Which dylib in OpenGL framework gets linked? (simple glut ex) johnMG 6 3,590 Oct 22, 2003 06:06 AM
Last Post: anarchie