All pastes #719269 Raw Edit

Stuff

public text v1 · immutable
#719269 ·published 2007-09-29 03:26 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_FULLSCREEN))
	{
		glfwTerminate();
		return 0;
	}

	glfwSetWindowTitle("My OpenGL test");

	while (1)
	{
		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;

		if (glfwGetKey('A'))
		{
			//player_angle -= 0.5;
			glRotatef(0.01, player_x, player_y, 1.0);
		}
		else if (glfwGetKey('S'))
		{
			//player_angle += 0.5;
			glRotatef(-0.01, player_x, player_y, 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_x - PLAYER_WIDTH / 2, player_y - PLAYER_LENGTH / 2);
			glVertex2f(player_x + PLAYER_WIDTH / 2, player_y - PLAYER_LENGTH / 2);
			glVertex2f(player_x + PLAYER_WIDTH / 2, player_y + PLAYER_LENGTH / 2);
			glVertex2f(player_x - PLAYER_WIDTH / 2, player_y + PLAYER_LENGTH / 2);
		glEnd();

		glfwSwapBuffers();

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

    glfwTerminate();

    return 0;
}