#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
void processInput(GLFWwindow* window);
using namespace std;
void RenderScene();
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//glfwWindowHint(GLFW_MAXIMIZED, true);
//glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "zi xi", nullptr, nullptr);
//GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "My Title", glfwGetPrimaryMonitor(), NULL);
glfwSetWindowOpacity(window, 0.8f);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
// Clear the colorbuffer
glClearColor(1.0f, 0.7f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
processInput(window);
RenderScene();
// Swap the screen buffers
glfwSwapBuffers(window);
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
}
// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return EXIT_SUCCESS;
}
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
cout << "1" << endl;
}
void RenderScene() {
glPointSize(5);
glColor3f(1, 0, 0);
glBegin(GL_POINTS);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
glEnd();
}
void RenderScene() {
glLineWidth(2);
glColor3f(1, 1, 0);
glBegin(GL_LINES);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
glEnd();
}
void RenderScene() {
glLineWidth(2);
glColor3f(1, 1, 0);
glBegin(GL_LINE_STRIP);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
//glVertex2f(.75, .75);
glVertex2f(0.9, 0.5);
//glVertex2f(0.9, 0.5);
glVertex2f(0.8, 0.3);
glEnd();
}
Draw GL_LINE_LOOP
void RenderScene() {
glLineWidth(2);
glColor3f(1, 1, 0);
glBegin(GL_LINE_LOOP);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
//glVertex2f(.75, .75);
glVertex2f(0.9, 0.5);
//glVertex2f(0.9, 0.5);
glVertex2f(0.8, 0.3);
glEnd();
}
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_TRIANGLES);
glVertex2f(.25, 0.25);
glVertex2f(.75, .75);
glVertex2f(0.9, 0.5);
glColor3f(1, 1, 0);
glVertex2f(-0.3f, -0.3f);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.3f, -0.3f);
glEnd();
}
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(0, 0);
glVertex2f(0.2, 0);
glColor3f(1, 1, 0);
glVertex2f(0.1, 0.1);
glVertex2f(0.3f, 0.1f);
glColor3f(1, 0, 0);
glVertex2f(0.2f, 0.2f);
glVertex2f(0.4f, 0.2f);
glEnd();
}
draw triangle fan
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0, 0);
glVertex2f(0.1, -0.1);
glVertex2f(0.2, 0);
glVertex2f(0.1f, 0.1f);
glVertex2f(-0.1f, 0.1f);
glVertex2f(-0.2f, 0.0f);
glVertex2f(-0.1f, -0.1f);
glEnd();
}
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0.2, 0.0f);
glVertex2f(0.2, 0.2);
glVertex2f(0.0f, 0.2f);
glEnd();
}
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0.2, 0.0f);
glVertex2f(0.3, 0.2);
glVertex2f(0.1f, 0.2f);
glEnd();
}
draw polygon
void RenderScene() {
glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
glVertex2f(0, 0);
glVertex2f(0.1, 0.0f);
glVertex2f(0.2, 0.1);
glVertex2f(0.1f, 0.2f);
glVertex2f(0, 0.2);
glVertex2f(-0.1f, 0.1f);
glEnd();
}