Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Lorrenz Attractor not linking

  1. #1
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3

    Lorrenz Attractor not linking

    I am trying to make 3D lorenz attractor but somehow not able to link it properly.

    My code where it is showing problem is:

    static void display(void)
    {
    int i;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glRotated(ph,1,0,0);
    glRotated(th,0,1,0);

    glBegin(GL_LINESTRIP);
    for (i=0;i<N;i++)
    {
    glColor3fv(color[i];
    glVertex3fv(pa[1]);
    }
    glEnd();

    glColor3f(1,1,1);
    glBegin(GL_LINES);
    glVertex3d(0,0,0);
    glVertex3d(1,0,0);
    glVertex3d(0,0,0);
    glVertex3d(0,1,0);
    glVertex3d(0,0,0);
    glVertex3d(0,0,1);
    glEnd();

    glRasterPos3d(1,0,0);
    Print("X");
    glRasterPos3d(0,1,0);
    Print("Y");
    glRasterPos3d(0,0,1);
    Print("Z");

    glFlush();
    glutSwapBuffers();
    }


    Error showing is:

    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glcolor3fv'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glvertex3d'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glvertex3d'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glvertex3d'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glvertex3d'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glprint'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glprint'
    /tmp/cc4Vqewz.o:attractor.c:function display: error: undefined reference to 'glprint'

    The command I tried is gcc attractor.c -lm -lGL -lGLU -lglut

    Kindly resolve the error. Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    791
    Please use [code][/code] around source code snippets. The error messages you posted refer to function names with all lower case letters, OpenGL functions use mixed case so that looks odd - do you have some macros #define'd that have the same name as OpenGL functions? Are those the first errors messages from the compiler/linker - in general it is often not very useful to look at any error but the very first, because they can be follow ups.

  3. #3
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3


    Code :
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <stdarg.h>
    #define GL_GLEXT_PROTOTYPES
    #ifdef __APPLE__
    #include <GLUT/glut.h>
    #else
    #include <GL/glut.h>
    #endif
     
    int th = 0;
    int ph = 0;
    double w = 1;
     
    double a = 10.0;
    double b = 28.0;
    double c = 2.6666;
     
    int N = 50000;
    float pa[50000][3];
    float color[50000][3];
     
     
    static void display(void)
    	{
    		int i;
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    		glLoadIdentity();
    		glRotated(ph,1,0,0);
    		glRotated(th,0,1,0);
     
    		glBegin(GL_LINE_STRIP);
    		for (i=0;i<N;i++)
    		{
    			glcolor3fv(color[i]);
    			glVertex3fv(pa[i]);
    		}
    		glEnd();
     
    		glColor3f(1,1,1);
    		glBegin(GL_LINES);
    		glVertex3d(0,0,0);
    		glVertex3d(1,0,0);
    		glVertex3d(0,0,0);
    		glVertex3d(0,1,0);
    		glVertex3d(0,0,0);
    		glVertex3d(0,0,1);
    		glEnd();
     
    		glRasterPos3d(1,0,0);
    		Print("X");
    		glRasterPos3d(0,1,0);
    		Print("Y");
    		glRasterPos3d(0,0,1);
    		Print("Z");
     
    		glWindowPos2i(5,5);
     
     
    	glFlush();
    	glutSwapBuffers();
    	}
     
     
    static void lorenz(void) 
    	{
    	int i;
    	double x = pa[0][0] = 1;
    	double y = pa[0][1] = 1;
    	double z = pa[0][2] = 1;
    	double w = pa[0][3] = 1;
    	double dt = 0.01;
     
    	for (i=0;i<N;i++)
    		{
    			double dx = a*(y-x);
    			double dy = x*(b-z)-y;
    			double dz = x*y-c*z;
     
    			x += dt*dx;
    			y += dt*dy;
    			z += dt*dz;
     
    			pa[i+1][0] = x;
    			pa[i+1][1] = y;
    			pa[i+1][2] = z;
    			pa[i+1][3] = w;
     
    			color[i+1][0] = x;
    			color[i+1][1] = y;
    			color[i+1][2] = z;
    		}
    	}
     
     
    void key(unsigned char ch,int x,int y)
    	{
    		if (ch == 27)
    		exit(0);
    		else if (ch == '0')
    		th = ph = 0;
    		else if (ch == 'q')
    		 {
    			a += 1.0;
    			lorenz();
    		}
    		else if (ch == 'a')
    		 {
    			a -= 1.0;
    			lorenz();
    		}
    		else if (ch == 'w')
    		{
    			b += 1.0;
    			lorenz();
    		}
    		else if (ch == 's')
    		{
    			b -= 1.0;
    			lorenz();
    		}
    		else if (ch == 'e')
    		{
    			c += 1.0;
    			lorenz();
    		}
    		else if (ch == 'd')
    		{
    			c -= 1.0;
    			lorenz();
    		}
    		else if (ch == '-')
    		{
    			w += 0.5;
    			lorenz();
    		}
    		else if (ch == '+')
    		{ 
    			w -= 0.5;
    			lorenz();
    		}
    	glutPostRedisplay();
    	}
     
     
    static void special(int key, int x, int y)
    	{
    		if (key == GLUT_KEY_RIGHT)
    		th += 5;
    		else if (key == GLUT_KEY_LEFT)
    		th -= 5;
    		else if (key == GLUT_KEY_UP)
    		ph += 5;
    		else if (key == GLUT_KEY_DOWN)
    		ph -= 5;
     
    		th %= 360;
    		ph %= 360;
     
    		glutPostRedisplay();
    	}
     
     
    static void reshape(int width, int height)
    	{
    		double w2h = (height>0) ? (double)width/height : 1;
    		int dim = 3;
    		glViewport(0,0, width,height);
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		glOrtho(-dim*w2h,+dim*w2h,-dim,+dim,-dim,+dim);
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
    	}
     
     
    int main(int argc, char* argv[]) 
    	{
    	lorenz();
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    	glutInitWindowPosition(50, 50);
    	glutInitWindowSize(500, 500);
    	glutCreateWindow("3D Lorenz Attractor");
    	glutDisplayFunc(display);
    	glutReshapeFunc(reshape);
    	glutSpecialFunc(special);
    	glutKeyboardFunc(key);
    	glutMainLoop();
    	return 0;
    	}

    Please check where I am going wrong. Thank you so much

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by linapr View Post
    Please check where I am going wrong.
    Where you are going wrong is in not posting any relevant information, e.g. which platform you're using, or which compiler, or anything else which might be relevant.

  5. #5
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3
    Thank you for your comment.

    I am working on ubuntu with gcc compiler. I have submission today but seems like I won't be able to provide the working code. I am working on ubuntu 12.04 and has freeglut3-dev installed, binutils-gold is also installed. I hve no idea why this code is not working. What else do you want to know to help me out?

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    791
    I've tried to compile what you posted, I get errors from the compiler - how did you get this to the linking stage? Anyway, in display:

    Code :
    glBegin(GL_LINE_STRIP);
    		for (i=0;i<N;i++)
    		{
    			glcolor3fv(color[i]);
    			glVertex3fv(pa[i]);
    		}
    		glEnd();

    glcolor3fv is misspelled (no mixed case) and the function Print() used further down in display is nowhere defined.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •