All pastes #719288 Raw Edit

Miscellany

public text v1 · immutable
#719288 ·published 2007-09-29 03:47 UTC
rendered paste body
#include <GL/glfw.h>

#define PLAYER_WIDTH 0.5
#define PLAYER_LENGTH 0.15

float player_x = 0;
float player_y = 0;
float player_angle = 160;

int main(void)
{
	glfwInit();

	if (!glfwOpenWindow(640, 480, 8, 8, 8, 8, 24, 0, GLFW_WINDOW))
	{
		glfwTerminate();
		return 0;
	}

	glfwSetWindowTitle("My OpenGL test");

	while (1)
	{
        glLoadIdentity();

		if (glfwGetKey(GLFW_KEY_UP))
			player_y += 0.0001;
		else if (glfwGetKey(GLFW_KEY_DOWN))
			player_y -= 0.0001;

		if (glfwGetKey(GLFW_KEY_LEFT))
			player_x -= 0.0001;
		else if (glfwGetKey(GLFW_KEY_RIGHT))
			player_x += 0.0001;

        // Apply translation to the current matrix
        glTranslatef(player_x, player_y, 0.0);

		if (glfwGetKey('A'))
		{
			player_angle -= 0.05;
		}
		else if (glfwGetKey('S'))
		{
			player_angle += 0.05;
		}

        // Apply rotation to the matrix
	    glRotatef(player_angle, 0.0, 0.0, 1.0);

		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

		glBegin(GL_QUADS);
			glVertex2f(-PLAYER_WIDTH, -PLAYER_LENGTH);
			glVertex2f(PLAYER_WIDTH, -PLAYER_LENGTH);
			glVertex2f(PLAYER_WIDTH, PLAYER_LENGTH);
			glVertex2f(-PLAYER_WIDTH, PLAYER_LENGTH);
		glEnd();

		glfwSwapBuffers();

		if (glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
			break;
	}

    glfwTerminate();

    return 0;
}