All pastes #1220969 Raw Edit

Stuff

public text v1 · immutable
#1220969 ·published 2008-10-06 19:25 UTC
rendered paste body
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <math.h>
#include <GL/glut.h>

static int _wsize_x = 200;
static int _wsize_y = 200;


/*
 * drawing function
 */
static void draw(int wx, int wy,
                 int px, int py,
                 float r, float g, float b)
{
    int wmax;
    float x, y;
    float edge_size;

    wmax = wx;
    if (wy > wmax) {
        wmax = wy;
    }
    edge_size = 1.0 / ((float)wmax - 0.0);
    x = (px - (wx >> 1)) * edge_size;
    y = (py - (wy >> 1)) * edge_size;
    x = (px) * edge_size;
    y = (py) * edge_size;
    printf("px,py %f %f\n", x, y);
	glColor4f(r, g, b, 1.0);
	glPushMatrix();
	glTranslatef(x, y, 0);
	glutSolidCube(edge_size);
	glPopMatrix();
}

/*
 * GLUT call back
 */
void display(void)
{
	/* clear buffer and setup matrix */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

    draw(2, 2, 0, 0, 1.0, 0.0, 0.0);
    draw(2, 2, 1, 0, 0.0, 1.0, 0.0);
    draw(2, 2, 0, 1, 0.0, 0.0, 1.0);
    draw(2, 2, 1, 1, 1.0, 1.0, 1.0);

	glutSwapBuffers();
}

void idle(void)
{
}

void keyboard(unsigned char key, int x, int y)
{
}

void motion(int x, int y)
{
}

void mouse(int button, int state, int x, int y)
{
}

void reshape(GLint size_x, GLint size_y)
{
	if (size_y == 0) 
		size_y = 1;
    _wsize_x = size_x;
    _wsize_y = size_y;
  
	glViewport(0, 0, size_x, size_y);

	glMatrixMode(GL_PROJECTION);

    glLoadIdentity();
    gluOrtho2D(0, 1.0, 0, 1.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int main(int argc, char *argv[])
{
	/* initialize GLUT */
	glutInit(&argc, argv);
	glutInitWindowSize(_wsize_x, _wsize_y);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("darwin");
	
    glClearColor(0.0, 0.0, 0.0, 0.0);


	/* Register callbacks */
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	glutIdleFunc(idle);

	/* start main loop */
	glutMainLoop();
	return 0;
}