Randomize number with OpenGL

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Randomize number with OpenGL

 
0
  #1
Feb 15th, 2005
I am taking a Computer Graphics course where we are doing some c++ programming using the OpenGL API. I'm writing a C++ program in Visual Studio.NET, where I've installed GLUT (Open GL Utility Toolkit). OpenGL, itself, apparently comes with VS.

The only include that I have in my one-file program is:
#include <GL/glut.h>


The program works fine up until the point where I need to randomize a number. When I try including stdlib.h or cstdlib in my file, I get an error message about redefinition and my program won't compile.

In the textbook the class is using, it shows rand() being used without having to include anything extra. I'm assuming it's somehow built into glut.h? However, even when I copy code directly out of a textbook example, I get the error message "unresolved external symbol referenced in function" and then "fatal error: 1 unresolved externals"

When I remove the line or two referencing rand() in my program, once again it compiles and runs fine. Please, how can I generate a random number from within an OpenGL program?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 30
Reputation: Intel is an unknown quantity at this point 
Solved Threads: 1
Intel Intel is offline Offline
Light Poster

Re: Randomize number with OpenGL

 
0
  #2
Feb 15th, 2005
Oh boy,
Make sure you include the .h files in your project - add them to your project.
Copy "glut32.dll" to your C:\WINDOWS\system\
Copy "glut32.lib" to your C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib
Create a directory called "gl" under
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\

and copy glut32.h to it, ie under
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\
i copied all the GLUT .h files there anyway.

When you create your project, click the project name then choose properties, From the Configuration list box, select All Configurations, In the left pane, select the Linker subtree and then the Input option. Add the given code to the Additional Dependencies text box in the right pane. This tells Visual Studio where to find GLUT. (Copy and Paste: opengl32.lib glu32.lib glut32.lib )

Good luck.
Intel
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Randomize number with OpenGL

 
0
  #3
Feb 15th, 2005
Thank you, Intel. However, all of that was done already And it works. I was able to create my first two OpenGL programs just fine ... this is the third project. The only time the program stops working is when I try to use rand(). It works other than that darn randomize!

Any other ideas?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 30
Reputation: Intel is an unknown quantity at this point 
Solved Threads: 1
Intel Intel is offline Offline
Light Poster

Re: Randomize number with OpenGL

 
0
  #4
Feb 16th, 2005
In C++, rand() is defined in
  1. #include <stdlib.h>
I used rand() and all i included is
  1. #include <GL/glut.h>
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 30
Reputation: Intel is an unknown quantity at this point 
Solved Threads: 1
Intel Intel is offline Offline
Light Poster

Re: Randomize number with OpenGL

 
0
  #5
Feb 16th, 2005
Try
  1. std::rand();
Here is how i used it
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <GL/gl.h>
  4. #include <GL/glu.h>
  5. .....
  6. double .... = std::rand();
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Randomize number with OpenGL

 
0
  #6
Feb 16th, 2005
This might sound silly silly, but when I did
  1. #include <GL/glut.h>
  2. #include <cstdlib>
I got a compile-time error message. But when I did
  1. #include <cstdlib>
  2. #include <GL/glut.h>
everything compiled and ran just fine. Either way, it all works now. Thank you for your help and support.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 30
Reputation: Intel is an unknown quantity at this point 
Solved Threads: 1
Intel Intel is offline Offline
Light Poster

Re: Randomize number with OpenGL

 
0
  #7
Feb 16th, 2005
#include <cstdlib> is declared in glut.h so when u declare it first it wont be redefined in glut.h , [#ifndef ... #def ... #endif]
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Randomize number with OpenGL

 
0
  #8
Feb 16th, 2005
Yes, but the problem is that when I only included glut.h, and not cstdlib or stdlib.h at all, I got a compiling error when I used rand() !!
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 30
Reputation: Intel is an unknown quantity at this point 
Solved Threads: 1
Intel Intel is offline Offline
Light Poster

Re: Randomize number with OpenGL

 
0
  #9
Feb 16th, 2005
My guess then is that rand is defined in the file space - glut.h, check it out and you'll see ....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC