Limitations:
- I can’t change the frameworks
- I have to use the functions in the
program (my beloved teacher doesn’t like us using functions given by any other than herself)
Here’s the code and it works just like this (just not as smooth as i would like it to)
#include<OpenGL/gl.h>
#include<OpenGL/glu.h>
#include<GLUT/glut.h>
#include <stdlib.h>
#include <math.h>
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<=cpoints;i++)
{
glBegin(GL_POINTS);
glVertex2i(xi,yi);
glEnd();
xi = xi+dx;
yi = xi*sin(xi);
}
glFlush();
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
/*printf("lower bound: ");
scanf(" %d",&lb);
printf("upper bound:");
scanf(" %d",&ub);
printf("Give me the number of points to plot (int)");
scanf(" %d",&cpoints);*/
glutInitWindowSize(500,500);
glutCreateWindow("Graph function in 2D");
init();
glutDisplayFunc(graphfunct2D);
glutMainLoop();
}
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)
Try something like this: