c++ - having issues using gl_VertexID to draw const vertices that are inside the shader -


hi there having problems gl_vertexid seems not updating or when use in opengl program draw vertices stored in shader vec4's,as far know should straightforward , job without problems or issues have done correctly unfortunately isnt showing

here :

my main program

#include "shaders.h"  int main(){  glfwinit();  glfwwindowhint(glfw_context_version_major, 4); glfwwindowhint(glfw_context_version_minor, 3); glfwwindowhint(glfw_opengl_profile, glfw_opengl_core_profile); glfwwindowhint(glfw_opengl_forward_compat, gl_true);  glfwwindowhint(glfw_resizable, gl_false);  glfwwindow* window = glfwcreatewindow(800, 600, "opengl", null, null);         glfwmakecontextcurrent(window);  glewexperimental = gl_true; glewinit();   //create vertex array object //vertex array object holds state  gluint vao; glgenvertexarrays(1, &vao); glbindvertexarray(vao);  //compile , link shaders here  gluint program = compile_shaders(); gluseprogram(program);  while(!glfwwindowshouldclose(window)) {     glfwswapbuffers(window);     glfwpollevents();      // clear screen black     glclearcolor(1.0f, 1.0f, 1.0f, 1.0f);     glclear(gl_color_buffer_bit);      // draw triangle constant values in shader     gldrawarrays(gl_triangles, 0, 3);     glflush();  }   } 

now problem when run program trying draw vertices in shader, , when run program blank screen , nothing drawn

here shades , shaders.cpp is:

#include "shaders.h"  gluint compile_shaders(void){    gluint vertex_shader;    gluint fragment_shader;    gluint program;  const glchar * vertex_shader_source = {        "#version 430 core\n"    "void main(void)\n"    "{\n"    "const vec4 vertices[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),\n"                                     "vec4(-0.25, -0.25, 0.5, 1.0),\n"                                     "vec4( 0.25, 0.25, 0.5, 1.0));\n"    "gl_position = vertices[gl_vertexid];\n"    "}\n" };   const glchar * fragment_shader_source = {       "#version 430 core\n"     "out vec4 color\n"     "void main(void)\n"     "{\n"     "color = vec4(0.0,0.8,1.0,1.0)\n"     "}\n" };    vertex_shader = glcreateshader(gl_vertex_shader);  glshadersource(vertex_shader, 1 , &vertex_shader_source, null);  glcompileshader(vertex_shader);   fragment_shader = glcreateshader(gl_fragment_shader);  glshadersource(fragment_shader, 1, &fragment_shader_source, null);  glcompileshader(fragment_shader);   program = glcreateprogram();  glattachshader(program, vertex_shader);  glattachshader(program, fragment_shader);  gllinkprogram(program);   gldeleteshader(vertex_shader);  gldeleteshader(fragment_shader);   return program; };  

this shader.h file in case need it

#include <gl/glew.h> #include <glfw/glfw3.h> #include <stdio.h> #include <stdlib.h> #include <time.h>  gluint compile_shaders(void); 


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -