#include <iostream>
#include<cmath>
// 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 lineDDA(int x0, int y0, int xEnd, int yEnd);
void setPixel(float x, float y);
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);
lineDDA(0, 600, 800, 0);
// 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 lineDDA(int x0, int y0, int xEnd, int yEnd)
{
glPointSize(3);
glColor3f(1, 1, 0.3);
int dx = xEnd - x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;
if (dx > dy)
{
steps = dx;
}
else
{
steps = dy;
}
xIncrement = (float)dx / steps;
yIncrement = (float)dy / steps;
setPixel(x, y);
for (int k = 0; k < steps; k++)
{
x += xIncrement;
y += yIncrement;
setPixel(x, y);
}
}
void setPixel(float x, float y)
{
float newx = 2 * x / WIDTH - 1;
float newy = 2 * y / HEIGHT - 1;
glBegin(GL_POINTS);
glVertex2f(newx, newy);
glEnd();
}