Created
July 14, 2019 04:16
-
-
Save batousik/66cfab7269e3e2df69a053acfb23661b to your computer and use it in GitHub Desktop.
opengl_test
This file contains 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
//#include <iostream> | |
// | |
// | |
//#include <cstdio> | |
//#include <cstdlib> | |
//#include <iostream> | |
//#include <fstream> | |
//#include <sstream> | |
//#include <glad/glad.h> | |
#include <GL/glew.h> | |
#include <GLFW/glfw3.h> | |
#include <iostream> | |
extern "C" | |
{ | |
#include <libavutil/frame.h> | |
} | |
int showGLWindow(uint8_t *data) { | |
GLFWwindow *window; | |
/* Initialize the library */ | |
if (!glfwInit()) | |
return -1; | |
/* Create buffer windowed mode window and its OpenGL context */ | |
window = glfwCreateWindow(800, 800, "Hello World", NULL, NULL); | |
if (!window) { | |
glfwTerminate(); | |
return -1; | |
} | |
/* Make the window's context current */ | |
glfwMakeContextCurrent(window); | |
if (glewInit() != GLEW_OK) | |
std::cout << "Error! Glew could not init\n"; | |
std::cout << "OpenGL using: " << glGetString(GL_VERSION) << std::endl; | |
int h = 800, w = 800; | |
GLuint g_texture = {}; | |
glGenTextures(1, &g_texture); | |
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |
glBindTexture(GL_TEXTURE_2D, g_texture); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, | |
h, 0, GL_RGB, GL_UNSIGNED_BYTE, | |
data); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, | |
GL_LINEAR); /* We will use linear interpolation for magnification filter */ | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | |
GL_LINEAR); /* We will use linear interpolation for minifying filter */ | |
/* Loop until the user closes the window */ | |
while (!glfwWindowShouldClose(window)) { | |
/* Render here */ | |
// Clear color and depth buffers | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_MODELVIEW); // Operate on model-view matrix | |
glEnable(GL_TEXTURE_2D); | |
GLuint texture = g_texture; | |
glBindTexture(GL_TEXTURE_2D, texture); | |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, 800, 800, GL_RGB, GL_UNSIGNED_BYTE, data); | |
// Draw a quad | |
glBegin(GL_QUADS); | |
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, 1.0f); | |
glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, -1.0f); | |
glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, -1.0f); | |
glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); | |
glEnd(); | |
glDisable(GL_TEXTURE_2D); | |
glBindTexture(GL_TEXTURE_2D, 0); | |
glFlush(); | |
/* Swap front and back buffers */ | |
glfwSwapBuffers(window); | |
/* Poll for and process events */ | |
glfwPollEvents(); | |
} | |
glfwTerminate(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment