-
OpenGL Not working......
Ok, so I am trying to do some stuff in OpenGL. I got Visual C++ .net a few months ago, but I haven't tryed opengl with it yet. I was using Dev C++ for a little while and that worked fine compiling opengl code. But when i try to compile the simplest of opengl code with Visual C++ I get an error:
Code:
fatal error C1010: unexpected end of file while looking for precompiled header directive
Here is the code I copied from someplace :) :
Code:
#include <GL/glut.h>
#include "stdlib.h"
#define RAMPSIZE 16
#define RAMP1START 32
#define RAMP2START 48
static float rotAngle = 0.;
/* Initialize antialiasing for color index mode,
* including loading a green color ramp starting
* at RAMP1START, and a blue color ramp starting
* at RAMP2START. The ramps must be a multiple of 16.
*/
void init(void)
{
int i;
for (i = 0; i < RAMPSIZE; i++) {
GLfloat shade;
shade = (GLfloat) i/(GLfloat) RAMPSIZE;
glutSetColor(RAMP1START+(GLint)i, 0., shade, 0.);
glutSetColor(RAMP2START+(GLint)i, 0., 0., shade);
}
glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth (1.5);
glClearIndex ((GLfloat) RAMP1START);
}
/* Draw 2 diagonal lines to form an X
*/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glIndexi(RAMP1START);
glPushMatrix();
glRotatef(-rotAngle, 0.0, 0.0, 0.1);
glBegin (GL_LINES);
glVertex2f (-0.5, 0.5);
glVertex2f (0.5, -0.5);
glEnd ();
glPopMatrix();
glIndexi(RAMP2START);
glPushMatrix();
glRotatef(rotAngle, 0.0, 0.0, 0.1);
glBegin (GL_LINES);
glVertex2f (0.5, 0.5);
glVertex2f (-0.5, -0.5);
glEnd ();
glPopMatrix();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D (-1.0, 1.0,
-1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h,
1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'r':
case 'R':
rotAngle += 20.;
if (rotAngle >= 360.) rotAngle = 0.;
glutPostRedisplay();
break;
case 27: /* Escape Key */
exit(0);
break;
default:
break;
}
}
/* Main Loop
* Open window with initial window size, title bar,
* color index display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_INDEX);
glutInitWindowSize (200, 200);
glutCreateWindow (argv[0]);
init();
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutDisplayFunc (display);
glutMainLoop();
return 0;
}
Help me. :(
-
I'm pretty certain you need to #include <gl/gl.h> to use some of the functions calls you use.
-
Nah, that didn't work. Can anyone give me some reliable code? Like, some code that intializes an opengl window, in windowed mode. Thanks! Also, do I have to link anything in the configurations to be able to compile opengl programs? I hope not, because I would feel really stupid :( There isn't an SDK is there?
EDIT: BTW I have the latest NVIDIA drivers installed, too.
-
You have to link OpenGL library files, but that isn't your problem right now. What kind of project are you using for this? It should be a empty windows application. This is looking for precompliled headers which means you aren't using the correct project type for this.
Plus I don't think you can run OpenGL programs like you are trying to do in the console. I don't have a lot of OpenGL experience being a DX guy, but I think you need to make a window, ie. using WinMain() etc.
-
I am using a win32 project. Also, I even tryed some opengl code that created a window. But when i tryed to compile it. It gave me that same error in my first post. So I DO have to link something. Well, can someone help me out there?
-
I believe the answer has been duly provided. Read.
www.amazon.com - Get a book about OpenGL.
-
If you are using GLUT, DON"T USE A WIN32 Project... use a regular console type one. And you probably have to have #include<windows.h> as your FIRST include.
-
Project -> Settings -> C/C++ Tab
From the drop-down box, select "Precompiled Headers". Now select the radio button that says "Not using precompiled headers".
These steps may vary a little bit depending on what version of MSVC you are using.
-
In the future, when you create a project, always select Empty Project in the create wizard to avoid this problem.
If you can't find the option bithub mentioned, you can also create a new empty project and import the source files into it.
-
Ok, I think I got it partially working after I followed a tutorial. Turns out I had to download GLUT, and put the .dll's into the system folder. And the lib and .h in the correct directory. I also linked it in Visual C++. But now when I compile I stuff, i get different errors. I don't get the same error that I mentioned before, so it must have found the .lib and stuff. But I still get some errors.
-
-
Ok, I used the code from nehe lesson 2. Here are my errors:
Code:
------ Build started: Project: dfjdj, Configuration: Debug Win32 ------
Linking...
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug/dfjdj.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\tony\My Documents\Visual Studio Projects\dfjdj\Debug\BuildLog.htm"
dfjdj - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
Here is the tutorial I was using: HERE
-
It isn't expecting you to use main as your entry point for some reason in the first error.
-
But main() is there ...
What's your current code? Still exactly the same as in the first post?
-
No, I said I used nehe's lesson # 2. I downloaded the Visual C++ .net version of the code, if that's correct.