Note that there are some explanatory texts on larger screens.

plurals
  1. PONested loop apparently not looping in PyOpenGL
    text
    copied!<p>I'm pretty sure that this is specifically my error in Python's looping syntax, but I can't for the life of me figure out what's wrong.</p> <p>I'm using Python on OSX with PyOpenGL and GLUT for a very basic program: it's intended to draw a 3D grid around (0,0,0). I've managed to produce the 2D grid at a given elevation (so there's a grid at y=10 from x=-10 to x=10 and from z=-10 to z=10), but I can't make it iterate through the y-coordinate.</p> <p><a href="http://i.imgur.com/zvsnv7k.png" rel="nofollow">This screenshot should help to show what I mean</a>. My intended scenario is that there would be ten of these flat grids above y=0, and ten below, forming a cube. Later on, too, I'll extend it to lines in the y-axis, but I've semi-achieved that before (same problem as I'm having now) so no big deal. </p> <p>Would someone please let me know what the problem is with my code? It seems like a fairly simple issue, but I've wasted a few hours on this and would really appreciate some help.</p> <p>A couple of disclaimers:</p> <p>I'm aware that GLUT is old tech and that most of this code is deprecated, but this project isn't about that.</p> <p>I'll need to go through and change the "-10 to 10" constants in the z- and x-coords at some point, but that method should be straightforward once I've got this y thing working.</p> <pre><code>from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * grid_range = 10 def DrawGLScene( ): i = 0 j = 0 fl_range = float(grid_range) while (j &lt;= (grid_range*2) ): while (i &lt;= (grid_range*2) ): # x grid glColor3f( 0.0, 1.0, 0.0 ) glBegin( GL_LINES ) glVertex3f( grid_range - i, grid_range - j, -10 ) glVertex3f( grid_range - i, grid_range - j, 10 ) glEnd( ) # z grid glColor3f( 0.0, 0.0, 1.0 ) glBegin( GL_LINES ) glVertex3f( -10, grid_range - j, grid_range - i ) glVertex3f( 10, grid_range - j, grid_range - i ) glEnd( ) i += 1 j += 1 </code></pre>
 

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