Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I edited your code and put a comment here and there:</p> <pre><code>void init() { /* One time OpenGL initialization would be textures and * other static stuff. Nothing like that here */ } /* CALLED TO DRAW THE HELICES */ void RenderHelix() { GLfloat x,y,z; float aspectratio; GLfloat c = 2.5f; //helical pitch GLfloat theta; //constant angle between tangent and x-axis GLfloat r = 4.5f; //radius //GLint i = 1; //loop through code to render 7 helices /* assuming w and h are globals or somehow else accessible */ aspectratio = (float)w/(float)h; glViewport(0,0,w,h); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat aspectratio = (GLfloat)w/(GLfloat)h; if(w&lt;=h) glFrustum(-10.f,10.f, -10.f/aspectratio, 10.f/aspectratio, 1.0f, 10.f); else glFrustum(-10.f*aspectratio,10.f*aspectratio,-10.f,10.f, 1.0f,10.f); /* enable depth testing, also make sure the right depth func is used */ glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); /* GREEN HELIX */ glLineWidth(8.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.f, 0.f, -4.5f); glPushMatrix(); /* this helix will be drawn in the center, as it's not moved anywhere. */ glBegin(GL_LINE_STRIP); glColor3f(0.0, 1.0, 0.0); /* trigonometric functions take radians, not degrees */ for(theta = 0; theta &lt;= M_PI2; theta += M_PI2*0.01;) { /* instead of calculating the helices a new each rendering * pass you should store them to a vertex array. */ x = r*cosf(theta); y = r*sinf(theta); z = c*theta; glVertex3f(x,y,z); } glEnd(); glPopMatrix(); /* Other 6 helices .... */ glScalef(1.0,1.0,12.0); glTranslatef(50.0, 100.0, 0.0); //Move Position of next helix, you may want to use glPushMatrix/glPopMatrix glRotatef(90.0, 0.0, 0.0, 0.0); // a null rotation, what's that's supposed to do? glFlush(); // redundant, glFlush is implied by SwapBuffers glutSwapBuffers(); } void Reshape(GLint w, GLint h) { /* Pleast don't set OpenGL stuff in the window reshape handler. * This just causes confusion, as soon one uses multiple projections * in a single rendering */ } </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