| | |
Randomize number with OpenGL
Thread Solved
![]() |
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:
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?
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?
•
•
Join Date: Feb 2005
Posts: 30
Reputation:
Solved Threads: 1
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
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
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?
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?
•
•
Join Date: Feb 2005
Posts: 30
Reputation:
Solved Threads: 1
In C++, rand() is defined in
I used rand() and all i included is
C++ Syntax (Toggle Plain Text)
#include <stdlib.h>
C++ Syntax (Toggle Plain Text)
#include <GL/glut.h>
•
•
Join Date: Feb 2005
Posts: 30
Reputation:
Solved Threads: 1
Try
Here is how i used it
C++ Syntax (Toggle Plain Text)
std::rand();
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <GL/gl.h> #include <GL/glu.h> ..... double .... = std::rand();
This might sound silly silly, but when I did
I got a compile-time error message. But when I did
everything compiled and ran just fine. Either way, it all works now. Thank you for your help and support.
C++ Syntax (Toggle Plain Text)
#include <GL/glut.h> #include <cstdlib>
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <GL/glut.h>
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() !!
![]() |
Similar Threads
- [seo] RSS2MYSQL - Randomize RSS (Show Off your Projects)
Other Threads in the C++ Forum
- Previous Thread: help getting !true bool to break out of program
- Next Thread: arrays???
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output parameter pointer problem program programming project python random read recursion reference rpg std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






