Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL VBO Drawing
    primarykey
    data
    text
    <p>I seem to be having some trouble drawing objects in OpenGL using VBOs. I've attempted to copy the example from: <a href="http://www.opengl.org/wiki/VBO_-_just_examples" rel="nofollow">http://www.opengl.org/wiki/VBO_-_just_examples</a> (number 2) but I can't get a plane to appear on screen.</p> <p>Vertex.h:</p> <pre><code>#include &lt;freeglut&gt; struct Vertex { GLfloat position[3]; GLfloat normal[3]; GLfloat *uvs[2]; unsigned short uvCount; }; </code></pre> <p>Triangles.h:</p> <pre><code>#include &lt;GL/glew.h&gt; #include "Vertex.h" class Triangles { public: Triangles(GLuint program, Vertex *vertices, unsigned int vertexCount, unsigned int *indices[3], unsigned int indiceCount); ~Triangles(); void Draw(); private: GLuint program; GLuint VertexVBOID; GLuint IndexVBOID; GLuint VaoID; unsigned int *indices[3]; unsigned int indiceCount; }; </code></pre> <p>Triangles.cpp:</p> <pre><code>#include "Triangles.h" #include &lt;stdio.h&gt; #include &lt;stddef.h&gt; Triangles::Triangles(GLuint program, unsigned int *indices[3], unsigned int indiceCount) { memcpy(this-&gt;indices, indices, sizeof(int) * indiceCount * 3); this-&gt;indiceCount = indiceCount; this-&gt;program = program; glGenVertexArrays(1, &amp;VaoID); glBindVertexArray(VaoID); glGenBuffers(1, &amp;VertexVBOID); glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertexCount, vertices, GL_STATIC_DRAW); GLuint attributeLocation = glGetAttribLocation(program, "position"); glEnableVertexAttribArray(attributeLocation); glVertexAttribPointer(attributeLocation, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(offsetof(Vertex, position))); attributeLocation = glGetAttribLocation(program, "normal"); glEnableVertexAttribArray(attributeLocation); glVertexAttribPointer(attributeLocation, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(offsetof(Vertex, normal))); glGenBuffers(1, &amp;IndexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 3 * indiceCount, indices, GL_STATIC_DRAW); }; Triangles::~Triangles() { glDisableVertexAttribArray(glGetAttribLocation(program, "position")); glDisableVertexAttribArray(glGetAttribLocation(program, "normal")); glDeleteBuffers(1, &amp;VertexVBOID); glDeleteBuffers(1, &amp;IndexVBOID); glDeleteVertexArrays(1, &amp;VaoID); } void Triangles::Draw() { glBindVertexArray(VaoID); glDrawElements(GL_TRIANGLES, indiceCount, GL_UNSIGNED_INT, 0); }; </code></pre> <p>Excerpt from main.cpp (creating triagle object):</p> <pre><code>Vertex vertices[4]; vertices[0].position[0] = -1; vertices[0].position[1] = 1; vertices[0].position[2] = 0; vertices[0].normal[0] = 0; vertices[0].normal[0] = 0; vertices[0].normal[0] = 1; vertices[0].uvCount = 0; vertices[1].position[0] = 1; vertices[1].position[1] = 1; vertices[1].position[2] = 0; vertices[1].normal[0] = 0; vertices[1].normal[0] = 0; vertices[1].normal[0] = 1; vertices[1].uvCount = 0; vertices[2].position[0] = 1; vertices[2].position[1] = -1; vertices[2].position[2] = 0; vertices[2].normal[0] = 0; vertices[2].normal[0] = 0; vertices[2].normal[0] = 1; vertices[2].uvCount = 0; vertices[3].position[0] = -1; vertices[3].position[1] = -1; vertices[3].position[2] = 0; vertices[3].normal[0] = 0; vertices[3].normal[0] = 0; vertices[3].normal[0] = 1; vertices[3].uvCount = 0; unsigned int **indices; indices = new unsigned int*[2]; indices[0] = new unsigned int[3]; indices[0][0] = 0; indices[0][1] = 1; indices[0][2] = 2; indices[1] = new unsigned int[3]; indices[1][0] = 2; indices[1][1] = 3; indices[1][2] = 0; Triangles *t = new Triangles(program, vertices, 4 indices, 2); </code></pre> <p>createShader(GLenum , char *):</p> <pre><code>GLuint createShader(GLenum type, char *file) { GLuint shader = glCreateShader(type); const char *fileData = textFileRead(file); glShaderSource(shader, 1, &amp;fileData, NULL); glCompileShader(shader); return shader; } </code></pre> <p>Shader loading:</p> <pre><code> GLuint v = createShader(GL_VERTEX_SHADER); GLuint f = createShader(GL_FRAGMENT_SHADER, "fragmentShader.frag"); program = glCreateProgram(); glAttachShader(program, v); glAttachShader(program, f); glLinkProgram(program); glUseProgram(program); </code></pre> <p>vertexShader.vert:</p> <pre><code>in vec3 position; in vec3 normal; out vec3 a_normal; void main() { gl_Position = vec4(position, 1.0); } </code></pre> <p>fragmentShader.frag:</p> <pre><code>in vec3 a_normal; out vec4 out_color; void main() { out_color = vec4(1.0, 1.0, 1.0, 1.0); } </code></pre> <p>Please let me know if more code is needed. As a side note everything compiles just fine, I just don't see the plane that I have constructed on screen (maybe because I didn't use colors?)</p> <p>My OpenGL information is as follows:</p> <ul> <li>Vendor: ATI Technologies Inc.</li> <li>Renderer: ATI Radeon HD 5700 Series</li> <li>Version: 3.2.9756 Compatibility Profile Context</li> <li>Extensions: extensions = GL_AMDX_name_gen_delete GL_AMDX_random_access_target GL_AMDX_vertex_shader_tessellator GL_AMD_conservative_depth GL_AMD_draw_buffers_blend GL_AMD_performance_monitor GL_AMD_seamless_cubemap_per_texture GL_AMD_shader_stencil_export GL_AMD_texture</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload