Results 1 to 3 of 3

Thread: please see what is wrong with this code?

  1. #1
    Guest

    please see what is wrong with this code?

    Hi I tried to run this code but it doesn't interact with my drawing immeditly .. so can u tell me what is wrong or can i find better programs like it?
    -----------------
    thanx
    ----------------------
    /* A simple curve drawing program, 1/31/01 by Mark Harris
    Illustrates mouse, mouse motion callback functions
    */

    #include <GL/glut.h>

    int squarecolor=1;
    int anchorx,anchory;
    int WindowWidth=500;
    int WindowHeight=500;

    void myinit(void)
    {

    /* attributes */

    glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */

    /* set up viewing */
    /* 500 x 500 window with origin lower left */

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 500.0, 0.0, 500.0);
    glMatrixMode(GL_MODELVIEW);
    }

    void display( void )
    {
    glClear(GL_COLOR_BUFFER_BIT); /*clear the window */
    glFlush(); /* clear buffers */
    }

    void mouse(int button,int state,int x,int y)
    {
    y=500-y; // convert system orientation
    anchorx=x;
    anchory=y;
    return;
    }

    void motion(int x, int y)
    {
    y=500-y; // convert system orientation
    glColor3f(1,0,0); /* draw in red */
    glBegin(GL_LINES);
    glVertex2f(anchorx,anchory);
    glVertex2f(x,y);
    glEnd();
    anchorx=x; // update anchor point
    anchory=y;
    }

    void main(int argc, char** argv)
    {

    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(WindowWidth,WindowHeight);
    glutInitWindowPosition(0,0); /* place window top left on display */
    glutCreateWindow("Draw"); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    myinit(); /* set attributes */

    glutMainLoop(); /* enter event loop */
    }

  2. #2
    Guest

    Re: please see what is wrong with this code?

    I think its not working because you need a glut Idle Function where you would call glutPostRedisplay(); This causes Glut to call the display function, The display function is not called automatically. You don't need the Idle function but it is normally a good place to call glutPostRedisplay(); from.

  3. #3
    Member Newbie
    Join Date
    Mar 2001
    Location
    Brest
    Posts
    39

    Re: please see what is wrong with this code?

    You should add a camera, if you want look at your drawing....
    gluLookAt(cx, cy, cz, tx, ty, tz, 0, 1, 0);
    with (cx,cy,cz) position of the camera
    (ty,ty,tz) target of the camera
    Then, you must add the method 'glutIdleFunc(glutIdle);'
    in this method (using for animation calculs generaly), you call the display function:
    example:

    void glutIdle(void)
    {
    if (ani)
    {
    rot += vec3_t(0.0, 1.5, 0.0);
    rot.Clamp(-360, 360);
    glutPostRedisplay();
    }
    }

    bye

Similar Threads

  1. what is wrong with my code?
    By alexopenglbeginner in forum OpenGL: Windows
    Replies: 1
    Last Post: 09-02-2009, 03:09 PM
  2. what is wrong with this code?
    By openman in forum OpenGL: Linux
    Replies: 1
    Last Post: 08-04-2008, 04:21 AM
  3. What wrong with my code?
    By johncsl82 in forum OpenGL: Basic Coding
    Replies: 21
    Last Post: 12-13-2003, 05:28 AM
  4. Help! What's wrong with this code?
    By Mr. Bitmap in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-03-2002, 12:04 AM
  5. What's wrong with my code???
    By Ashtray_Waterloo in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-22-2000, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean