Results 1 to 4 of 4

Thread: Why doesnt this work? OpenGL code...

  1. #1
    theduck
    Guest

    Why doesnt this work? OpenGL code...

    why doesn't this work?
    it dont rotate or change color!

    [pascal]//OPEN-GL TEMPLATE///////
    //DUCK ENTERPRISES 2005//
    //COLIN DRAKE////////////

    Program Tutor02;

    Uses GL, GLUT;




    ////////////////////////////////////////////////////////////////////////////////declaration of constants and variables
    var rtri:Extended;
    var myvar1:Extended;
    var new_t:integer;
    var done:integer;
    ////////////////////////////////////////////////////////////////////////////////program initialization



    ////////////////////////////////////////////////////////////////////////////////misc



    ////////////////////////////////////////////////////////////////////////////////list creation



    ////////////////////////////////////////////////////////////////////////////////drawing
    //
    //
    //callback
    Procedure reshape(width, height : LongInt); stdcall;
    Var aspect : glFloat;
    Begin
    aspect := width/height;
    //setup new projection matrix which depends on window size
    glMatrixMode(GL_PROJECTION); //switch to projection-matrix
    glLoadIdentity; //setup standard matrix
    glFrustum(-1.0*aspect,1.0*aspect,1.0,-1.0,1.0,20.0); //setup viewing matrix

    glMatrixMode(GL_MODELVIEW); //switch back to the modelview-matrix
    glLoadIdentity; //setup standard matrix

    End;
    ////////////////////////////////////////////////////////////////////////////////CREATE EVERYTHING

    Procedure draw; stdcall;
    Begin

    if new_t=0 then
    begin
    myvar1:=1.0;
    new_t:=1;
    end;

    //Reminder: To Create Tris, glB Flag is: GL_TRIANGLES
    //Reminder: To Create Quads, glB Flag is: GL_QUADS

    //clear the color buffer

    glClear(GL_COLOR_BUFFER_BIT); //clear the screen or window

    myvar1:=myvar1-0.01;
    rtri:=rtri+1;

    glRotatef(rtri,1.0,1.0,1.0);

    //do some drawing
    glBegin(GL_TRIANGLES); //draw something with 4 vertexes
    glColor3f(myvar1,0.0,0.0); //color
    glVertex3f(-0.8, -0.5, -2.0); //first vertex
    glColor3f(0.0,0.0,myvar1); //color
    glVertex3f(-0.0, 0.5, -2.0); //second vertex
    glColor3f(0.0,myvar1,0.0); //color
    glVertex3f( 0.8, -0.5, -2.0); //third vertex
    glEnd; //thats 3 vertexes, so it draws it!!


    glFlush; //tell OpenGL to flush internal buffers
    //glSwapBuffers; //we actually don't use the double-buffer


    End;
    ////////////////////////////////////////////////////////////////////////////////START UP CODE

    Begin

    myvar1:=1.0;
    //OpenGL and GLUT initialization
    glutInit(@argc, argv);
    glShadeModel(GL_SMOOTH);
    glutCreateWindow('My First OpenGL Application');

    //callback registration
    glutDisplayFunc(@draw);
    glutReshapeFunc(@reshape);


    ////////////////////////////////////////////////////////////////////////////////MAIN LOOP
    while done=0 do
    begin
    glutMainLoop; //<<Render...
    glutDisplayFunc(@draw);
    glutReshapeFunc(@reshape);
    end;

    End.
    [/pascal]

  2. #2

    Why doesnt this work? OpenGL code...

    glutDisplayFunc only gets called when the window needs to be redrawn. You can call glutPostRedisplay tell glut that the window needs to be redisplayed.

  3. #3
    theduck
    Guest

    :( Doesn't work still...

    Ummm... it still doesn't work...

  4. #4

    Why doesnt this work? OpenGL code...

    Check your "D:\fpc\source\packages\extra\opengl\examples" directory for a GLUTDEMO. Be sure it's on your drive letter ... it works well. You need GLUT's DLL to run, in your directory.

Bookmarks

Posting Permissions

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