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 4 of 4

Thread: make point move

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2

    Angry make point move

    hello all i'am writing a code to make point move in screen by display it and clear it but that's dose not work can anyone help me ??
    this is the code

    Code glsl:
    #include<Windows.h>
    #include <GL/glut.h>
     
     
    #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )  // Remove console window
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glut32.lib")
     
     
    GLdouble width, height;  
     
     
     
    void display()
    {
     
     
     
     
     
     
      glClearColor(1.0, 1.0,1.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT);
     
     
     
      glColor3f(0.0, 0.0, 0.0);
     
     
     
      for (int i=50;i<500;i++)
      {
     
          glBegin(GL_POINTS);
          glVertex2d(i,50);
     
     
    Sleep(1000); 
     
     
     
     
      glClear(GL_COLOR_BUFFER_BIT);
     
     glEnd();
     
     
     
      glFlush();
    }
     
     
    }
     
     
     
     
     
      void reshape(int w, int h)
    {
      /* save new screen dimensions */
      width =  w;
      height = h;
     
      /* tell OpenGL to use the whole window for drawing */
      glViewport(0, 0, width, height);
     
      /* do an orthographic parallel projection with the coordinate
         system set to first quadrant, limited by screen/window size */
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0.0, width, 0.0, height);
    }
     
    void main(int argc, char *argv[])
    {
      /* initialize GLUT, let it extract command-line 
         GLUT options that you may provide 
         - NOTE THE '&' BEFORE argc */
      glutInit(&argc, argv);
     
      /* specify the display to be single 
         buffered and color as RGBA values */
      glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
     
      /* set the initial window size */
      glutInitWindowSize(500, 500);
     
      /*set position of widow on the screen*/
      glutInitWindowPosition(0,0);
     
      /* create the window with title*/
      glutCreateWindow("Firts");
     
      /* --- register callbacks with GLUT --- */
     
      /* register function to handle window resizes */
      glutReshapeFunc(reshape);
     
      /* register function that draws in the window */
      glutDisplayFunc(display);
     
      /* start the GLUT main loop */
      glutMainLoop();
     
     
    }
    Last edited by Dark Photon; 02-22-2013 at 06:40 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,191
    Please use [code]...[/code] or [highlight=cpp]...[/highlight] around your code blocks. I've inserted them for you.

    You didn't specify what your problem is. Without knowing that, hard to guess how to help you.

    For starters, try putting a glutPostRedisplay (); at the bottom of your display() method. This is not the ideal method, but if you're having trouble getting it rendering this'll do it.

    Also consider using DOUBLE rather than SINGLE buffering, and put a glutSwapBuffers() right before your glutPostRedisplay(). With sync-to-vblank on, this'll draw once per refresh.

  3. #3
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2
    hello,
    the screen dose not clear after each step

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    you cannot call glClear between glBegin and glEnd. it doesn't work like that and will generate GL_INVALID_OPERATION. it should be either before drawing a primitive or after. but it's not your biggest problem. you haven't got any clue about how rendering isdone, even at such basic level. this code is hilarious. google "opengl tutorial" and read at least something like this. if you want to know how particular function works - just google it's name and open first link leading to OpenGL.org. if you're not interested - no one will do your homework here.

Posting Permissions

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