Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Strange glDrawArrays minimum vertex count?

  1. #1
    Newbie Newbie
    Join Date
    Apr 2016
    Posts
    1

    Unhappy Strange glDrawArrays minimum vertex count?

    Hello, I've been using OpenGL for well over a year now. I'm fairly comfortable with it, and I've always been able to diagnose issues myself, but this one just has me completely lost. While writing some very basic code my program continuously crashes while executing glDrawArrays under certain circumstances. Here are a few basic examples. In this scenario I'm just trying to draw a single point for debug proposes. This point is a VBO defined as follows:
    Code :
    float data[3] = {1.0F, 1.0F, 1.0F};
     
    glGenBuffers(1, &vboSquare);
    glBindBuffer(GL_ARRAY_BUFFER, vboSquare);
    glBufferData(GL_ARRAY_BUFFER, 3*sizeof(float), &data, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    Very basic. This point is nothing more than three floats. Now here is where things get strange. My render code is as follows:
    Code :
    glUseProgram(GL->shaderPassthrough);
    	float data[16];
    	glGetFloatv(GL_MODELVIEW_MATRIX, data);
    	glUniformMatrix4fv(glGetUniformLocation(GL->shaderPassthrough, "inModelViewMatrix"), 1, GL_FALSE, &data[0]);
     
    glBindBuffer(GL_ARRAY_BUFFER, vboSquare);
    	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    	glDrawArrays(GL_POINTS, 0, 1);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glUseProgram(0);

    This code crashes (by which I mean I get the windows "This program has stopped responding, would you like to blah blah blah" message and then the program closes). I pinpointed the cause of the crash to be the final argument in glDrawArrays(...). For whatever reason the code refuses to work unless the last argument (the vertex count) is at least 257. What is even more bizarre is that if I were to delete the glVertexAttribPointer(...) line then the vertex count can be as low as 129 without crashing.

    I've created multiple programs using code almost identical to this, in fact to save time this program is nothing more than a duplicated project of another program that works 100% as intended. The shaders are the same, the vertex attribute pointers are all set up the same. Everything is identical, yet in this program glDrawArrays(...) won't let me draw small VBOs.

    If anyone has any information regarding this please share as I'm pulling the last bit of my hair out trying to do the most simple of tasks.
    Last edited by SChaseGarrett; 04-07-2016 at 11:45 PM. Reason: Grammar

  2. #2
    Intern Contributor
    Join Date
    Feb 2016
    Posts
    64
    OpenGL is hard to debug without tools, you should try to use gdb (for general programming, a must-have for not going crazy) and apitrace which logs all calls and enables you to see the OpenGL state at any given moment in your program. It's necessary if you don't want to spend days trying to debug.

    On your problem though, I can't see what's wrong. I'll try to replicate the problem later but in the meantime you should see what error is returned precisely.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Your glBufferData call should be "data", or "&data[0]", instead of "&data".

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,848
    Quote Originally Posted by mhagain View Post
    Your glBufferData call should be "data", or "&data[0]", instead of "&data".
    It doesn't matter. Both expressions point to the start of the array. They have different types, but (assuming that this is C) the expression is implicitly converted to "const GLvoid*" (the type of the third argument to glBufferData). The result is the same either way.

    In C++, you'd need an explicit cast, but the result would still be the same either way.

  5. #5
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    882
    Quote Originally Posted by SChaseGarrett View Post
    I'm pulling the last bit of my hair out trying to do the most simple of tasks.
    * In the code you pasted, you haven't enabled any vertex attributes, thus no attributes will be fetched, thus your VBO is ignored. In a compatibility profile context, this means your draw call should be completely no-oped. In a core profile context, your vertex shader will still be executed N times, but all input attributes will come from the current vertex.
    * Crashes are among the easier sort of problem to debug. Look at the crash log. What is the driver doing when it crashes?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •