Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to set the projection matrix inside the reshape function (<code>resize()</code>), which also automatically solves the problem of the user resizing the window:</p> <pre><code>void resize(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, w, h, 0); } </code></pre> <p>And then in your draw function, make sure that the matrix mode is model-view:</p> <pre><code>void draw() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ... } </code></pre> <p>Other problems with your code:</p> <ul> <li>You probably shouldn't be calling <code>glutPostRedisplay()</code> at the end of <code>draw()</code>. This is going to make your CPU run at 100%. You can instead use <code>glutTimerFunc()</code> to still have updates every some number of milliseconds.</li> <li>In <code>processMouse()</code>, you're using <code>wsprintf()</code> on an array of <code>char</code>s: <code>wsprintf()</code> takes an array of wide characters (<code>wchar_t</code>), so you should make the local variable <code>s</code> of type <code>wchar_t[]</code>, or use <code>sprintf()</code> and <code>MessageBoxA()</code> instead of <code>wsprintf()</code> and <code>MessageBoxW()</code> (to which <code>MessageBox()</code> expands as a macro when compiling a Unicode application, which I'm assuming you're doing). You're also vulnerable to a buffer overflow -- you should use a buffer of at least 12 characters, even though realistically you'll never be passed a very large <code>x</code> value. Finally, you should also use <code>snprintf()/wsnprintf()</code> instead of <code>sprintf()/wsprintf()</code> to protect against the buffer overflow.</li> </ul>
 

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