Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to plot using openGL using user-given values / asking for values?
    text
    copied!<p><strong>Limitations:</strong></p> <ul> <li>I can't change the frameworks </li> <li>I have to use the functions in the program (my beloved teacher doesn't like us using functions given by any other than herself)</li> </ul> <p>Here's the code and it works just like this (just not as smooth as i would like it to)</p> <pre><code>#include&lt;OpenGL/gl.h&gt; #include&lt;OpenGL/glu.h&gt; #include&lt;GLUT/glut.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; int lb=-30, ub=30; double cpoints=9999999; void init (void) { glClearColor(1,1,1,1); glMatrixMode(GL_PROJECTION); gluOrtho2D(-30,30,-30,30); } void graphfunct2D(void) { double dx, xi, yi; dx = (ub-lb)*1.0/cpoints; glColor3f(0,0,0); glClear(GL_COLOR_BUFFER_BIT); xi = lb; yi = xi*sin(xi); int i; for (i=0; i&lt;=cpoints;i++) { glBegin(GL_POINTS); glVertex2i(xi,yi); glEnd(); xi = xi+dx; yi = xi*sin(xi); } glFlush(); } int main (int argc, char** argv) { glutInit(&amp;argc, argv); /*printf("lower bound: "); scanf(" %d",&amp;lb); printf("upper bound:"); scanf(" %d",&amp;ub); printf("Give me the number of points to plot (int)"); scanf(" %d",&amp;cpoints);*/ glutInitWindowSize(500,500); glutCreateWindow("Graph function in 2D"); init(); glutDisplayFunc(graphfunct2D); glutMainLoop(); } </code></pre> <p>I want the user to be able to provide the upper and lower bounds and plot the function based on those two but when i run the program with the inputs uncommented it doesnt display anything (when i dont ask for them and use the ones i defined it runs just fine)</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