Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 26th, 2017 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #include <string>
  6.  
  7. // include glfw
  8. // include glad
  9.  
  10.  
  11. static void glfwErrorCallback(int error, const char *description)
  12. {
  13.     // printf("GLFW Error: [%d]: %s\n", error, description);
  14.  
  15.     fprintf(stdout, "GLFW Error: [%d]: %s\n", error, description);
  16.     fprintf(stderr, "GLFW Error: [%d]: %s\n", error, description);
  17.  
  18.     exit(EXIT_FAILURE);
  19. }
  20.  
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24.     if (!glfwInit())
  25.     {
  26.         fprintf(stderr, "Failed to initialize GLFW\n");
  27.  
  28.         glfwTerminate();
  29.  
  30.         // return EXIT_FAILURE;
  31.         exit(EXIT_FAILURE);
  32.     }
  33.  
  34.     glfwSetErrorCallback(glfwErrorCallback);
  35.  
  36.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  37.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  38.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  39.     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  40.  
  41.     glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  42.  
  43.     GLFWwindow *window = glfwCreateWindow(800, 600, "OpenGL", NULL, NULL);
  44.  
  45.     glfwMakeContextCurrent(window);
  46.  
  47.  
  48.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  49.     {
  50.         glfwTerminate();
  51.  
  52.         fprintf(stderr, "Failed to load OpenGL functions and extensions\n");
  53.  
  54.         // return EXIT_FAILURE;
  55.         exit(EXIT_FAILURE);
  56.     }
  57.  
  58.     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  59.  
  60.     GLchar *vertexShaderSource =
  61.         "#version 150\n"
  62.         "in vec2 position;\n"
  63.         "in vec2 tex_coord;\n"
  64.         "out vec2 Tex_coord;\n"
  65.         "void main() {\n"
  66.         "   gl_Position = vec4(position, 0.0, 1.0);\n"
  67.         "   Tex_coord = tex_coord;\n"
  68.         "}\n";
  69.  
  70.     GLchar *fragmentShaderSource =
  71.         "#version 150\n"
  72.         "in vec2 Tex_coord;\n"
  73.         "out vec4 outColor;\n"
  74.         "uniform sampler2D tex;\n"
  75.         "void main() {\n"
  76.         "   outColor = texture(tex, Tex_coord);\n"
  77.         "}\n";
  78.  
  79.     GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
  80.     GLuint frag_shader = glCreateShader(GL_FRAGMENT_SHADER);
  81.  
  82.     GLint compile_status;
  83.  
  84.     glShaderSource(vertex_shader, 1, &vertexShaderSource, NULL);
  85.     glCompileShader(vertex_shader);
  86.  
  87.     glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &compile_status);
  88.     if (compile_status != GL_TRUE) {
  89.         char buffer[512];
  90.         glGetShaderInfoLog(vertex_shader, 512, NULL, buffer);
  91.         throw std::runtime_error(buffer);
  92.     }
  93.  
  94.     glShaderSource(frag_shader, 1, &fragmentShaderSource, NULL);
  95.     glCompileShader(frag_shader);
  96.  
  97.     glGetShaderiv(frag_shader, GL_COMPILE_STATUS, &compile_status);
  98.     if (compile_status != GL_TRUE) {
  99.         char buffer[512];
  100.         glGetShaderInfoLog(frag_shader, 512, NULL, buffer);
  101.         throw std::runtime_error(buffer);
  102.     }
  103.  
  104.  
  105.     GLuint shader_prog = glCreateProgram();
  106.     glAttachShader(shader_prog, vertex_shader);
  107.     glAttachShader(shader_prog, frag_shader);
  108.     glBindFragDataLocation(shader_prog, 0, "outColor");
  109.     glLinkProgram(shader_prog);
  110.     glUseProgram(shader_prog);
  111.  
  112.  
  113.     GLuint vao;
  114.     glGenVertexArrays(1, &vao);
  115.     glBindVertexArray(vao);
  116.  
  117.  
  118.     const static GLfloat vertices[] = {
  119.         // Position   Tex-coords
  120.         -1.0f,  1.0f, 0.0f, 0.0f, // Top-left
  121.         1.0f,  1.0f, 1.0f, 0.0f, // Top-right
  122.         1.0f, -1.0f, 1.0f, 1.0f, // Bottom-right
  123.         -1.0f, -1.0f, 0.0f, 1.0f  // Bottom-left
  124.     };
  125.  
  126.     GLuint vbo;
  127.     glGenBuffers(1, &vbo);
  128.     glBindBuffer(GL_ARRAY_BUFFER, vbo);
  129.     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
  130.  
  131.     const static GLuint elements[] = {
  132.         0, 1, 2,
  133.         2, 3, 0
  134.     };
  135.  
  136.     GLuint ebo;
  137.     glGenBuffers(1, &ebo);
  138.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  139.     glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STREAM_DRAW);
  140.  
  141.     GLint pos_attrib = glGetAttribLocation(shader_prog, "position");
  142.     glVertexAttribPointer(pos_attrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
  143.     glEnableVertexAttribArray(pos_attrib);
  144.  
  145.     GLint tex_coord_attrib = glGetAttribLocation(shader_prog, "tex_coord");
  146.     glEnableVertexAttribArray(tex_coord_attrib);
  147.     glVertexAttribPointer(tex_coord_attrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
  148.  
  149.  
  150.     const GLsizei textureWidth = 2, textureHeight = 2;
  151.  
  152.     GLfloat pixels[textureWidth * textureHeight * 3] = {
  153.         1.0f, 0.0f, 0.0f,
  154.         0.0f, 1.0f, 0.0f,
  155.         0.0f, 0.0f, 1.0f,
  156.         1.0f, 1.0f, 0.0f,
  157.     };
  158.  
  159.     GLuint texture;
  160.     glGenTextures(1, &texture);
  161.     glBindTexture(GL_TEXTURE_2D, texture);
  162.  
  163.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_RGB, GL_FLOAT, pixels);
  164.  
  165.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  166.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  167.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  168.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  169.  
  170.  
  171.     glActiveTexture(GL_TEXTURE0);
  172.     glBindTexture(GL_TEXTURE_2D, texture);
  173.     glUniform1i(glGetUniformLocation(shader_prog, "tex"), 0);
  174.  
  175.  
  176.     while (!glfwWindowShouldClose(window))
  177.     {
  178.         glClear(GL_COLOR_BUFFER_BIT);
  179.  
  180.         glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  181.  
  182.         GLenum err = glGetError();
  183.         if (err)
  184.             printf("Error: %d\n", err);
  185.  
  186.         glfwSwapBuffers(window);
  187.         glfwPollEvents();
  188.     }
  189.  
  190.     glfwDestroyWindow(window);
  191.  
  192.     glfwTerminate();
  193.  
  194.     return EXIT_SUCCESS;
  195. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top