Note that there are some explanatory texts on larger screens.

plurals
  1. POVBO dissapearing, bad Matrix?
    primarykey
    data
    text
    <p>I'm not sure why but my VBO is disappearing after one frame (initial frame shows it at the origin improperly angled) Below is the code for my matrix class, the draw method, and the vertex shader.</p> <pre><code>Matrix::Matrix() { for (int i = 0; i &lt; 16; i++) { values[i] = 0; } } Matrix Matrix::operator*(const Matrix &amp;matrix) { Matrix result; for (int i = 0; i &lt; 4; i++) { for (int j = 0; j &lt; 4; j++) { for (int k = 0; k &lt; 4; k++) { result.values[i * 4 + j] += this-&gt;values[i * 4 + k] * matrix.values[k * 4 + j]; } } } return result; } Matrix Matrix::Perspective(float fov, float aspect, float znear, float zfar) { Matrix matrix; float xymax = znear * tan(fov * 0.00872664); float q = -(zfar * znear) / (zfar - znear); float val = znear / xymax; matrix.values[0] = val / aspect; matrix.values[5] = val; matrix.values[10] = q; matrix.values[11] = -1; matrix.values[14] = 2 * q; return matrix; } Matrix Matrix::LookAt(Vector3f eye, Vector3f target, Vector3f up) { Vector3f zaxis = Vector3f::Normalize(target - eye); Vector3f xaxis = Vector3f::Normalize(Vector3f::CrossProduct(up, zaxis)); Vector3f yaxis = Vector3f::CrossProduct(zaxis, xaxis); // vy doesn't need to be normalized because it's a cross product of 2 normalized vectors Matrix viewMatrix; viewMatrix.values[0] = xaxis.x; viewMatrix.values[1] = xaxis.y; viewMatrix.values[2] = xaxis.z; viewMatrix.values[3] = 0; viewMatrix.values[4] = yaxis.x; viewMatrix.values[5] = yaxis.y; viewMatrix.values[6] = yaxis.z; viewMatrix.values[7] = 0; viewMatrix.values[8] = zaxis.x; viewMatrix.values[9] = zaxis.y; viewMatrix.values[10] = zaxis.z; viewMatrix.values[11] = 0; viewMatrix.values[12] = 0; viewMatrix.values[13] = 0; viewMatrix.values[14] = 0; viewMatrix.values[15] = 1; Matrix translationMatrix = Matrix::Identity(); translationMatrix.values[12] = -eye.x; translationMatrix.values[13] = -eye.y; translationMatrix.values[14] = -eye.z; return translationMatrix * viewMatrix; } Matrix Matrix::Identity() { Matrix matrix; matrix.values[0] = 1; matrix.values[5] = 1; matrix.values[10] = 1; matrix.values[15] = 1; return matrix; } </code></pre> <p>Variables:</p> <pre><code>static const GLfloat g_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; GLuint vertexbuffer; GLuint programID; </code></pre> <p>Draw method:</p> <pre><code>void draw() { glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(programID); Matrix projection = Matrix::Perspective(45.0f, (float)(screen_size.x) / screen_size.y, 0.1f, 1000.0f); Matrix view = Matrix::LookAt(Vector3f(4, 3, 3), Vector3f(0, 0, 0), Vector3f(0, 1, 0)); Matrix model = Matrix::Identity(); Matrix mvp = projection * view * model; GLuint matrixID = glGetUniformLocation(programID, "mvp"); glUniformMatrix4fv(matrixID, 1, GL_FALSE, mvp.values); int positionId = glGetAttribLocation(programID, "position"); glEnableVertexAttribArray(positionId); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer(positionId, 3, GL_FLOAT, GL_FALSE, 0, (void *)0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(positionId); glutSwapBuffers(); } </code></pre> <p>Vertex Shader:</p> <pre><code>in vec3 position; uniform mat4 mvp; void main() { gl_Position = mvp * vec4(position, 1); } </code></pre>
    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