Maverika
May 11th, 2004, 12:40 PM
Hi,
Does anyone know which is the polygon filling algorithm in c++?
It can be done with this code, but what i want is which is the algorithm that is behind this ready made function glBegin( GL_POLYGON ) of open gl.
#include <iostream>
#include <cmath>
#include <windows.h>
#include <gl/Gl.h>
#include <gl/Glu.h>
#include <gl/glut.h>
#include <cmath>
using std::cout;
using std::cin;
int x[4], y[4];
void drawPolygon( int n, int *x, int *y ) {
int i;
glBegin( GL_POLYGON );
for (i = 0; i < n; i++ ) {
glVertex2i( x[i], y[i] );
}
glEnd( );
}
//---------------------------------------------------------------------
void myKeyboard(unsigned char key, int mouse_x, int mouse_y) {
switch (key) {
case 'a' :
glBegin( GL_POLYGON );
drawPolygon( 4, x, y );
x[0] = 300; y[0] = 300;
x[1] = 150; y[1] = 100;
x[2] = 50; y[2] = 200;
x[3] = 200; y[3] = 400;
glFlush();
glEnd( );
break;
}
}
//---------------------------------------------------------------------
void myInit(void) {
//Set background color
glClearColor(1.0, 1.0, 1.0, 0.0);
//Set background color
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(10.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 480.0, 0.0);
}
//-----------------------------------------------------------------------
void myDisplay(void) {
//Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glEnd();
glFlush();
}
//-----------------------------------------------------------------------
void main(int argc, char **argv) {
//Initialize the toolkit
glutInit(&argc, argv);
//Set the display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
//Set window size
glutInitWindowSize(640,480);
//Set the window position on screen
glutInitWindowPosition(100,150);
//Open the screen window
glutCreateWindow("Polygon");
//Register callback functions
glutDisplayFunc(myDisplay);
// glutReshapeFunc(myReshape);
glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop();
}
If anyone has a code or knows a link with the polygon filling algorithm please reply
Thanks
Does anyone know which is the polygon filling algorithm in c++?
It can be done with this code, but what i want is which is the algorithm that is behind this ready made function glBegin( GL_POLYGON ) of open gl.
#include <iostream>
#include <cmath>
#include <windows.h>
#include <gl/Gl.h>
#include <gl/Glu.h>
#include <gl/glut.h>
#include <cmath>
using std::cout;
using std::cin;
int x[4], y[4];
void drawPolygon( int n, int *x, int *y ) {
int i;
glBegin( GL_POLYGON );
for (i = 0; i < n; i++ ) {
glVertex2i( x[i], y[i] );
}
glEnd( );
}
//---------------------------------------------------------------------
void myKeyboard(unsigned char key, int mouse_x, int mouse_y) {
switch (key) {
case 'a' :
glBegin( GL_POLYGON );
drawPolygon( 4, x, y );
x[0] = 300; y[0] = 300;
x[1] = 150; y[1] = 100;
x[2] = 50; y[2] = 200;
x[3] = 200; y[3] = 400;
glFlush();
glEnd( );
break;
}
}
//---------------------------------------------------------------------
void myInit(void) {
//Set background color
glClearColor(1.0, 1.0, 1.0, 0.0);
//Set background color
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(10.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 480.0, 0.0);
}
//-----------------------------------------------------------------------
void myDisplay(void) {
//Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glEnd();
glFlush();
}
//-----------------------------------------------------------------------
void main(int argc, char **argv) {
//Initialize the toolkit
glutInit(&argc, argv);
//Set the display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
//Set window size
glutInitWindowSize(640,480);
//Set the window position on screen
glutInitWindowPosition(100,150);
//Open the screen window
glutCreateWindow("Polygon");
//Register callback functions
glutDisplayFunc(myDisplay);
// glutReshapeFunc(myReshape);
glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop();
}
If anyone has a code or knows a link with the polygon filling algorithm please reply
Thanks