diff options
| author | Andrew <saintruler@gmail.com> | 2019-05-05 20:38:16 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2019-05-05 20:38:16 +0400 |
| commit | 15ccb946f43283bfc91d80ddf012d9ae2a0333ed (patch) | |
| tree | c6715caebbed0eeb66db23d2180b2d2893f8cdf0 /Canvas.h | |
| parent | 1d3889e93f547df9f6c578b107552807c27fc6d4 (diff) | |
Diffstat (limited to 'Canvas.h')
| -rw-r--r-- | Canvas.h | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/Canvas.h b/Canvas.h deleted file mode 100644 index b2f943d..0000000 --- a/Canvas.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// Created by saintruler on 04.05.19. -// - -#ifndef OPENGLTEST_CANVAS_H -#define OPENGLTEST_CANVAS_H - -#include <glad/glad.h> -#include <GLFW/glfw3.h> - -#include <iostream> - -struct Color -{ - unsigned int r = 0, g = 0, b = 0; -}; - -class Canvas -{ -public: - Canvas(int width, int height) - { - this->width = width; - this->height = height; - - canvas = (unsigned char*) malloc(width * height * 3); - glGenTextures(1, &texture); - } - - void SetPixel(int x, int y, Color color) - { - glBindTexture(GL_TEXTURE_2D, texture); // all upcoming GL_TEXTURE_2D operations now have effect on this texture object - - // set texture wrapping to GL_REPEAT (default wrapping method) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - // set texture filtering parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - canvas[y * width * 3 + x * 3 + 0] = color.r; - canvas[y * width * 3 + x * 3 + 1] = color.g; - canvas[y * width * 3 + x * 3 + 2] = color.b; - - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, width, 0, GL_RGB, GL_UNSIGNED_BYTE, canvas); - glGenerateMipmap(GL_TEXTURE_2D); - } - - unsigned int* GetTexture() - { - return &(this->texture); - } - -private: - int width, height; - unsigned char* canvas; - unsigned int texture; -}; - -#endif //OPENGLTEST_CANVAS_H |