I have written a simple openGL code to render a triangle, it is compiled successfully but failed to render triangle. Only create a window as such there is no error return by glGetError()
api call. Same code works fine on AMD R9 GPU. Driver installation is also correct as I'm able to run glxdemos like glxgears or glxhead without any error.
Please help me to catch root cause of this issue.
here is my system configuration. CPU - intel i5 7400 (Kaby Lake 630 HD GPU) OS - Ubuntu 16.04 64-bit MESA - 3.0 v17.03
here is my code to render a triangle.
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(int agrc, char **argv)
{
//do windowing related stuff here
if ( !glfwInit())
{
printf("Error: Failed to initialize GLFW\n");
return -1;
}
GLFWwindow* window = glfwCreateWindow(800, 600, "Triangle", NULL, NULL);
if (window == NULL)
{
printf("Failed to create GLFW window\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
printf("Error: Failed to initialize GLEW\n");
return -1;
}
//declare vertices
GLfloat verts[] =
{
+0.0f, +0.5f, +0.0f,
-0.5f, -0.5f, +0.0f,
+0.5f, -0.5f, +0.0f,
};
//VBO related activity
//declare VAO, VBO
GLuint VAO, VBO, EBO;
//get unique name/ID
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
//glGenBuffers(1, &EBO);
// Bind VAO first, then bind and set VBOs and then configure vertex attributes
//bind VAO
glBindVertexArray(VAO);
//bind VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
//copy data to GPU
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
do{
glfwPollEvents();
}while(glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);
return 0;
}