# Thread: curve in C & SDL

1. ## curve in C & SDL

Hello world

I am looking for a ready C program that plot a math

curve, say for example y = sin(x); using the SDL library

2. Are you ready enough to have read through the example programs on the SDL home page?

3. There's also an SDL forum you can find via the SDL homepage.

4. yes Salem , enough to understand the code, my pb is having an urgent need to do numerical analysis, not to start learning SDL.

5. Originally Posted by lazakal
yes Salem , enough to understand the code, my pb is having an urgent need to do numerical analysis, not to start learning SDL.
How are you going to do this, using SDL, without learning SDL? If you are okay with C, I am sure it will not take you more than 4-10 hours to figure this out. If you are no good with C, then just looking at someone else's example will not help you (and I am positive there are a ton of such examples available on the web anyway). Altho actually drawing a 2D curve using trig is dead simple, graphics libraries are not completely trivial to initialize and use.

Since you haven't started yet, I'd recommend openGL instead for stuff like this (just an opinion).
Code:
```#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>
#include <stdio.h>
#include <math.h>

#define VOL 100
#define GL_PI 3.1415f

void scene() {
GLfloat i;
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0f,0.0f,0.0f,1.0f);
glPointSize(10.0f);
glBegin(GL_POINTS);
glVertex3i(0,0,0);
glEnd();
glColor4f(1.0f,1.0f,1.0f,1.0f);
glPointSize(2.0f);
glBegin(GL_POINTS);					/* creates an oval */
for (i=0.0; i<(2.0*GL_PI); i+=0.1) glVertex3f(sin(i)*20.0,cos(i)*10.0,0.0);
glEnd();
glutSwapBuffers();
}

void setup(float R, float G, float B) {
GLdouble N=0-VOL;
glClearColor(R,G,B,1.0f);
glMatrixMode(GL_PROJECTION);
glOrtho(N,VOL,N,VOL,N,VOL);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char *argv[]) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("openGL test");
glutDisplayFunc(scene);

setup(0.0,0.0,0.0);

glutMainLoop();
return 0;
}```
If you just want someone to write the code for you, try "rent-a-coder".

6. Oh, well, if it's urgent, then that puts a whole different slant on it.
How To Ask Questions The Smart Way

Rhett

7. 1 MB excuses, for you Salem and our smart guy, for my bugs; I try later to learn the synthax.

thanks, only , to Epy, but the MathGL is a C++ lib.

Hé smart guy, wait a minute, can you talk the admin to delete few records...

Popular pages Recent additions