PDA

View Full Version : make point move



eng.ftoom
02-22-2013, 04:37 PM
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


#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();


}

Dark Photon
02-22-2013, 06:41 PM
Please use
... or ... 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.

eng.ftoom
02-23-2013, 08:17 AM
hello,
the screen dose not clear after each step

Nowhere-01
02-23-2013, 09:19 AM
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 (http://lazyfoo.net/tutorials/OpenGL/index.php). 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.