[ create a new paste ] login | about

Link: http://codepad.org/5NtbmT5o    [ raw code | output | fork ]

C++, pasted on Apr 11:
#include<GL/glut.h>
#include <stdlib.h>
#include <math.h>

/* Set initial display-window size. */
GLsizei winWidth = 600, winHeight = 600;

/* Set range for world coordinates. */
GLfloat xwcMin = 0.0, xwcMax = 255.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;

class wcPt2D {
public:
	GLfloat x, y;
};

typedef GLfloat Matrix3x3 [3][3];

Matrix3x3 matComposite;

const GLdouble pi = 3.14159;

void init (void)
{
	/* Set color of display window to white. */
	glClearColor (1.0, 1.0, 1.0, 0.0);
}


/* Using the composite matrix, calculate transformed coordinates. */


void triangle (wcPt2D * verts)
{
	GLint k;

	glBegin (GL_TRIANGLES);
	for(k = 0; k < 3; k++)
		glVertex2f (verts [k].x, verts [k].y);
	glEnd();
}

void displayFcn (void)
{
	/* Define initial position for triangle. */
	GLint nVerts = 3;
	wcPt2D verts [3] = { {10.0, 25.0}, {125.0, 25.0}, {60.0, 60} };

	/* Calculate position of triangle centroid. */
	wcPt2D centroidPt;

	GLint k, xSum = 0, ySum = 0;
	for (k = 0; k < nVerts; k++) {
		xSum += verts [k].x;
		ySum += verts [k].y;
	}
	centroidPt.x = GLfloat (xSum) / GLfloat (nVerts);
	centroidPt.y = GLfloat (ySum) / GLfloat (nVerts);

	glClear (GL_COLOR_BUFFER_BIT);	// Clear display window.

	glColor3f (1.0, 0.5, 0.5);		// Set initial fill color.
	triangle (verts);				// Display colored triangle.

	glColor3f(1.0, 1.0, 0.0);	//Set color for transformed triangle.
	
	/* Raster transformation methods */

	GLubyte data [115 * 35 * 3];
	glPixelStorei (GL_PACK_ALIGNMENT, 1);
	glReadPixels(10, 25, 115, 35, GL_RGB, GL_UNSIGNED_BYTE, data);

	glRasterPos2i(50,50);	
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
	glDrawPixels(35, 115, GL_RGB, GL_UNSIGNED_BYTE, data);
	

	glFlush ( );
}

void winReshapeFcn (GLint newWidth, GLint newHeight)
{
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ( );
	gluOrtho2D (xwcMin, xwcMax, ywcMin, ywcMax);

	glClear (GL_COLOR_BUFFER_BIT);
}

void main (int argc, char ** argv)
{
	glutInit (&argc, argv);
	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
	glutInitWindowPosition (50,50);
	glutInitWindowSize (winWidth, winHeight);
	glutCreateWindow ("Geometric Transformation Sequence");

	init ( );
	glutDisplayFunc (displayFcn);
	glutReshapeFunc (winReshapeFcn);

	glutMainLoop ( );
}


Output:
1
2
3
Line 19: error: GL/glut.h: No such file or directory
Line 6: error: 'GLsizei' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: