Last active
August 29, 2015 14:11
-
-
Save Prince781/b5f0296a28dda6b70659 to your computer and use it in GitHub Desktop.
GLFW demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* test GLFW */ | |
| #include <GLFW/glfw3.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| #define WIDTH 1280 | |
| #define HEIGHT 720 | |
| #define TITLE "glfw demo" | |
| #define error_callback(err, descr) puts(descr); | |
| #define get_t_angle(time, interv)\ | |
| (sinf((fmod(time,interv)/interv) * 2*M_PI)) | |
| int main(int argc, char *argv[]) | |
| { | |
| GLFWwindow *window; | |
| if (!glfwInit() | |
| || !(window = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL))) | |
| return -1; | |
| glfwMakeContextCurrent(window); | |
| /* render */ | |
| while (!glfwWindowShouldClose(window)) { | |
| int width, height; | |
| double time; | |
| float ratio, angle; | |
| glfwGetFramebufferSize(window, &width, &height); | |
| glViewport(0, 0, width, height); | |
| time = glfwGetTime(); | |
| ratio = width / (float) height; | |
| glClearColor(0.f, 0.f, 0.f, 1.f); | |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| glMatrixMode(GL_PROJECTION); | |
| glLoadIdentity(); | |
| glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); | |
| angle = -get_t_angle(glfwGetTime(), 20.f); | |
| glMatrixMode(GL_MODELVIEW); | |
| printf("angle: %f\n", angle); | |
| glRotatef(angle, 0.f, 0.f, 1.f); | |
| glBegin(GL_TRIANGLES); | |
| glColor3f(1.f, 0.f, 0.f); | |
| glVertex3f(-0.6f, -0.4f, 0.f); | |
| glColor3f(0.f, 1.f, 0.f); | |
| glVertex3f(0.6f, -0.4f, 0.f); | |
| glColor3f(0.f, 0.f, 1.f); | |
| glVertex3f(0.f, 0.6f, 0.f); | |
| glColor3f(0.7f, 0.3f, 0.5f); | |
| glVertex3f(0.7f, 0.3f, 0.f); | |
| glColor3f(0.7f, 0.3f, 0.5f); | |
| glVertex3f(-0.7f, -0.3f, 0.f); | |
| glColor3f(0.1f, 0.3f, 0.5f); | |
| glVertex3f(0.2f, 0.9f, 0.f); | |
| glEnd(); | |
| glfwSwapBuffers(window); | |
| glfwPollEvents(); | |
| } | |
| glfwDestroyWindow(window); | |
| glfwTerminate(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # makefile for glfw | |
| CFLAGS=$(shell pkg-config --cflags glfw3) | |
| LDFLAGS=$(shell pkg-config --libs glfw3) -lGL -lm | |
| all: | |
| $(CC) $(CFLAGS) glfwtest.c -o glfw_test $(LDFLAGS) | |
| clean: | |
| $(RM) glfw_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment