Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is right here:</p> <pre><code>glGenTextures(1, &amp;_pm_tex_id[0]); ... _pm_tex_id[0] = glGetUniformLocation(_shaders.id(), "pauseMenuTex"); </code></pre> <p>The first statement creates a texture object and stores it into <code>_pm_tex_id[0]</code>. The next statement <em>overwrites</em> the texture object with a <em>uniform location</em>. Thus, you <em>lose</em> the texture object. It's no different from calling <code>new</code> to get a pointer, then overwriting that pointer later; you can't get it back.</p> <p>The reason why your code "works" with in <a href="https://stackoverflow.com/a/12170425/734069">your revised solution</a> is because you <em>kept</em> it bound to the context (in a different slot). You bound it to fill it with data, but you never unbound it. Thus, the context still has that texture object you lost track of.</p> <p>You need to store the texture name and the sampler uniform location <em>separate</em>. You should use better naming conventions than "id"; uniform locations shouldn't have the same kinds of naming convention as OpenGL object names. That way, you won't confuse them. I would suggest "unif" for uniforms instead of "id".</p> <hr> <p>Other things that aren't wrong, just not necessarily useful.</p> <p>You frequently call:</p> <pre><code>glEnableVertexAttribArray(0); </code></pre> <p>For no reason. You can't make attribute 0 <em>more</em> enabled than the first time you enabled it ;)</p> <p>You also allocate a lot of arrays of 1 item. That's <em>really</em> unnecessary. If you only want one VAO, just make a <code>GLuint</code> variable. When you need to generate it, just take it's address.</p> <p>Also, stop allocating so much memory period. If you need an array, use a <code>std::vector</code> (you can get a pointer to the array in the exact same way you currently do: <code>&amp;vec[0]</code>). This way, you won't have to remember to delete the memory; C++ will do it for you when the object is destroyed. You're already using C++, so you may as well actually use the language.</p>
 

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