Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Interactive Graphics

From ZeroWiki
Revision as of 19:07, 30 September 2015 by imported>wjh0470

Contents

Source code

주석은 차후에 다시

#include <gl\freeglut.h>

void Line()
{
	glLineWidth(5);
	glColor3f(0, 0, 0);
	glBegin(GL_LINES);
	glVertex2f(-1.0, 1.0);
	glVertex2f(1.0, -1.0);
	glEnd();
}

void Square()
{
	glColor3f(1, 0, 0);
	glBegin(GL_LINE_LOOP);
	glVertex2f(-0.7, 0.7);
	glVertex2f(-0.7, 0.2);
	glVertex2f(-0.2, 0.2);
	glVertex2f(-0.2, 0.7);
	glEnd();
}

void display()
{
	glClearColor(1, 1, 1, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	Line();
	Square();
	glFlush();
}

int main(int argc, char**argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Homework0_1");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
#include <gl\freeglut.h>
#include <diging.h>

float speed = 0;

void Rec(float locationX, float locationY, float size)
{
	vec2 rec[4] = { { -size + locationX, size + locationY }, { size + locationX, size + locationY },
	{ size + locationX, -size + locationY }, { -size + locationX, -size + locationY } };
	glBegin(GL_QUADS);
	for (int i = 0; i < 4;i++)
		glVertex2fv(rec[i]);
	glEnd();
}

void idle()
{
	speed += 0.0005;
	glutPostRedisplay();
}

void display()
{
	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mat4 m(1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(matrix_to_float(m));
	m *= Translate(speed, 0.0, 0.0);
	glPushMatrix();
	glLoadMatrixf(matrix_to_float(m));
	glColor3f(1, 1, 1);
	Rec(-1.0, 0.2, 0.2);
	m *= Translate(speed, 0.0, 0.0);
	glPushMatrix();
	glLoadMatrixf(matrix_to_float(m));
	glColor3f(0, 0, 0);
	Rec(-1.0, -0.2, 0.2);
	glutSwapBuffers();
}

int main(int argc, char**argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowPosition(200, 200);
	glutInitWindowSize(600, 600);
	glutCreateWindow("Homework2-1");
	glutIdleFunc(idle);
	glutDisplayFunc(display);
	glutMainLoop();

	return 0;
}
  1. include <gl\freeglut.h>
  2. include <math.h>
  1. define Round 0.2
  2. define PI 3.145926
  3. define radi2theta(x) x*PI/180.0

void cycle(float x, float y, float r, float g, float b) { float dx = 0, dy = 0; glColor3f(r, g, b); glBegin(GL_POLYGON); for (float i = 0; i < 360; i += 0.01) { dx = Round*cos(radi2theta(i)); dy = Round*sin(radi2theta(i)); glVertex2f(x + dx, y + dy); } glEnd(); }

void display() { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT);

cycle(-0.7, 0.7, 1, 0, 0); cycle(-0.25, 0.7, 0, 1, 0); cycle(0.2, 0.7, 0, 0, 1);

glFlush(); }

int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600, 600); glutInitWindowPosition(200, 200); glutCreateWindow("Homework0_3"); glutDisplayFunc(display); glutMainLoop(); return 0; }