Note that there are some explanatory texts on larger screens.

plurals
  1. POOpengl 3.3 rendering nothing
    primarykey
    data
    text
    <p>I'm trying to create my own lib that can simplify code, so I'm trying to write the tutorials that we can found on web using my lib but I'm have some trouble and I don't know why it's rendereing nothing. so this is my main file</p> <pre><code>#include "../../lib/OpenGLControl.h" #include "../../lib/Object.h" #include &lt;iostream&gt; using namespace std; using namespace sgl; int main(){ OpenGLControl sglControl; sglControl.initOpenGL("02 - My First Triangle",1024,768,3,3); GLuint VertexArrayID; glGenVertexArrays(1, &amp;VertexArrayID); glBindVertexArray(VertexArrayID); //trconfigurações do triangulo vector&lt;glm::vec3&gt; vertices; vertices.push_back(glm::vec3(-1.0f,-1.0f,0.0f)); vertices.push_back(glm::vec3(1.0f,-1.0f,0.0f)); vertices.push_back(glm::vec3(0.0f,1.0f,0.0f)); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Object triangle(vertices); do{ glClear(GL_COLOR_BUFFER_BIT); triangle.render(GL_TRIANGLES); glfwSwapBuffers(); } while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &amp;&amp; glfwGetWindowParam( GLFW_OPENED ) ); glDeleteVertexArrays(1, &amp;VertexArrayID); glfwTerminate(); return 0; } </code></pre> <p>and this is my Object class functions.</p> <pre><code>#include "../lib/Object.h" sgl::Object::Object(){ this-&gt;hasColor = false; } sgl::Object::Object(std::vector&lt;glm::vec3&gt; vertices){ for(int i = 0; i &lt; vertices.size(); i++) this-&gt;vertices.push_back(vertices[i]); glGenBuffers(1, &amp;vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, this-&gt;vertexBuffer); glBufferData(GL_ARRAY_BUFFER, this-&gt;vertices.size()*sizeof(glm::vec3),&amp;vertices[0], GL_STATIC_DRAW); } sgl::Object::~Object(){ glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDeleteBuffers(1,&amp;(this-&gt;vertexBuffer)); glDeleteBuffers(1,&amp;(this-&gt;colorBuffer)); } void sgl::Object::render(GLenum mode){ // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, this-&gt;vertexBuffer); glVertexAttribPointer( 0, // The attribute we want to configure 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); cout&lt;&lt;vertices.size()&lt;&lt;endl; glDrawArrays(mode, 0, vertices.size()); glDisableVertexAttribArray(0); } void sgl::Object::setColor(std::vector&lt;glm::vec3&gt; color){ for(int i = 0; i &lt; color.size(); i++) this-&gt;color.push_back(color[i]); glGenBuffers(1, &amp;(this-&gt;colorBuffer)); glBindBuffer(GL_ARRAY_BUFFER, this-&gt;colorBuffer); glBufferData(GL_ARRAY_BUFFER, color.size()*sizeof(glm::vec3),&amp;color[0], GL_STATIC_DRAW); this-&gt;hasColor = true; } void sgl::Object::setVertices(std::vector&lt;glm::vec3&gt; vertices){ for(int i = 0; i &lt; vertices.size(); i++) this-&gt;vertices.push_back(vertices[i]); glGenBuffers(1, &amp;vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, this-&gt;vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(glm::vec3),&amp;vertices[0], GL_STATIC_DRAW); } </code></pre> <p>the tutorial that I rewtriting is it:</p> <pre><code>/* Copyright 2010 Etay Meiri This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;. Tutorial 03 - First triangle */ #include &lt;stdio.h&gt; #include &lt;GL/glew.h&gt; #include &lt;GL/freeglut.h&gt; #include "math_3d.h" GLuint VBO; static void RenderSceneCB() { glClear(GL_COLOR_BUFFER_BIT); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); glutSwapBuffers(); } static void InitializeGlutCallbacks() { glutDisplayFunc(RenderSceneCB); } static void CreateVertexBuffer() { Vector3f Vertices[3]; Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f); Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f); Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f); glGenBuffers(1, &amp;VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); } int main(int argc, char** argv) { glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(1024, 768); glutInitWindowPosition(100, 100); glutCreateWindow("Tutorial 03"); InitializeGlutCallbacks(); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); glutMainLoop(); return 0; } </code></pre> <p>if some one can find the error please help me!</p>
    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.
    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