Thread: curve in C & SDL

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    3

    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. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Are you ready enough to have read through the example programs on the SDL home page?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    There's also an SDL forum you can find via the SDL homepage.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    3
    yes Salem , enough to understand the code, my pb is having an urgent need to do numerical analysis, not to start learning SDL.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by lazakal View Post
    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);
    	glLoadIdentity();
    	glOrtho(N,VOL,N,VOL,N,VOL);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
    	 
    
    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".
    Last edited by MK27; 01-22-2010 at 12:36 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Oh, well, if it's urgent, then that puts a whole different slant on it.
    How To Ask Questions The Smart Way

    Rhett
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    3

    Wink

    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 subscribe to a feed

Similar Threads

  1. SDL project setup
    By rogster001 in forum C Programming
    Replies: 22
    Last Post: 08-28-2009, 08:05 AM
  2. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  3. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM