Open GL using Visual C++ 6

Hi
Thanks in advance
I can not run Open Gl in Visual C++ in in Windows OS, My Open Gl program runs on Unix OS perfectly Can anyone tell me how can solve this problem.
Your help would highly appreciated

There is a number of things you should look out for. First if you are using VC++ and your program has a main() instead of WinMain() as an entry point then you might wanna set up the project as a Win32 Console Application instead of just Win32 Application. If you want good sample programs that you can use as the infrastructure check out NeHe Tutorials at nehe.gamedev.net, that site has tutorials on how to initialise openGL under Windows, that is your primary problem.

Are you using Glut? Why can’t you run it under VC++? Compiler errors? Linker errors? Run-time errors? More info is required.

good questions Deiussum

This the errors and warnings I get when I compiling it

Compiling…
ck1.c
c:\my documents\level2\sfe208\opengl\ck1.c(26) : warning C4305: ‘initializing’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(38) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(39) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(40) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(44) : warning C4013: ‘glutPostRedisplay’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(84) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(84) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(85) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(85) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(86) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(86) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(87) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(87) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(97) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(98) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(98) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(99) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(99) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(100) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(100) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(101) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(101) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(110) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(110) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(111) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(112) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(112) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(113) : warning C4305: ‘function’ : truncation from 'const double ’ to 'float ’
c:\my documents\level2\sfe208\opengl\ck1.c(240) : warning C4013: ‘glutSwapBuffers’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(128) : warning C4101: ‘bottomRx’ : unreferenced local variable
c:\my documents\level2\sfe208\opengl\ck1.c(128) : warning C4101: ‘bottomRy’ : unreferenced local variable
c:\my documents\level2\sfe208\opengl\ck1.c(127) : warning C4101: ‘topLx’ : unreferenced local variable
c:\my documents\level2\sfe208\opengl\ck1.c(127) : warning C4101: ‘topLy’ : unreferenced local variable
c:\my documents\level2\sfe208\opengl\ck1.c(271) : error C2065: ‘GLUT_LEFT_BUTTON’ : undeclared identifier
c:\my documents\level2\sfe208\opengl\ck1.c(271) : error C2051: case expression not constant
c:\my documents\level2\sfe208\opengl\ck1.c(273) : error C2065: ‘GLUT_DOWN’ : undeclared identifier
c:\my documents\level2\sfe208\opengl\ck1.c(290) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(291) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(294) : warning C4013: ‘glutIdleFunc’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(301) : error C2065: ‘GLUT_RIGHT_BUTTON’ : undeclared identifier
c:\my documents\level2\sfe208\opengl\ck1.c(301) : error C2051: case expression not constant
c:\my documents\level2\sfe208\opengl\ck1.c(334) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(339) : warning C4244: ‘=’ : conversion from 'double ’ to 'float ', possible loss of data
c:\my documents\level2\sfe208\opengl\ck1.c(356) : warning C4013: ‘glutInit’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(359) : warning C4013: ‘glutInitDisplayMode’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(359) : error C2065: ‘GLUT_DOUBLE’ : undeclared identifier
c:\my documents\level2\sfe208\opengl\ck1.c(359) : error C2065: ‘GLUT_RGB’ : undeclared identifier
c:\my documents\level2\sfe208\opengl\ck1.c(361) : warning C4013: ‘glutInitWindowSize’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(363) : warning C4013: ‘glutInitWindowPosition’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(365) : warning C4013: ‘glutCreateWindow’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(371) : warning C4013: ‘glutDisplayFunc’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(374) : warning C4013: ‘glutReshapeFunc’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(377) : warning C4013: ‘glutMouseFunc’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(380) : warning C4013: ‘glutKeyboardFunc’ undefined; assuming extern returning int
c:\my documents\level2\sfe208\opengl\ck1.c(384) : warning C4013: ‘glutMainLoop’ undefined; assuming extern returning int
Error executing cl.exe.

openGl.exe - 7 error(s), 48 warning(s)

That’s a few warnings there. The warnings aren’t much to worry about. You’re either using double variables in functions that are looking for a float, or using floating point literals. If you have functions like so…

glVertex3f(0.1, 0.1, 0.1);

You’ll get those warnings and can fix it by appending an f to the numbers like so…

glVertex3f(0.1f, 0.1f, 0.1f);

If you are using double variables, just change them to float variables instead. (Or change the glf functions to gld.)

Are you including glut.h? It appears that it’s not being included, which would explain a number of your Glut errors.

The bottomRX, bottomRY, topLx, topLy stuff are just warnings that you never actually use those within their scope.

The case expression not constant probably means you’re trying to do something like…

int n=10;

select(someInt)
{
case n: // n is not constant. This is a no-no
}

Either that or you’re trying to use a select/case on a string. I don’t remember if that gives that same error, though.

[This message has been edited by Deiussum (edited 11-21-2000).]

Come to think of it, that case error is probably caused from you trying to do a case on one of those undefined Glut definitions.

Another qustion:
I use MFC and OpenGL. Everything is working fine, but I would like to see some example projects made with MFC and OpenGL.

Especially I am interestes landscapes and so on. Does anyone know any good place for examples?

Since you 're using glut there are some standard things you must do in order to compile it under Visual C++ and i will try to present them all even though some of them might seem obvious.

First, your Project must be a Win32 Console Application.
Second you must find these files glut.h, glut32.dll and glut32.lib.

glut32.dll goes in the windows\system directory.

glut32.lib goes in a subdirectory named “lib” in your Visual C++ install directory.(Try to find it because i don’t remember the exact path)

And finally you may put glut.h in include\gl directory again in your Visual C++ install directory.

Now the main code.

You must include

#include <windows.h>
#include <gl/glut.h>
#include <gl/gl.h>
…other stuff

And finally.

Go to Project->Settings->Link(tab) and in the edit box entitled Object/Library modules add to the end or the beggining glut32.lib(i don’t know if it matters but anyway).

Then finally, rebuild your Project. I think the “… undefined” errors will be eliminated.

To verifiy if this is the error you can add the
#include “…”
and compile. If you haven’t include the libs the you will get some linking errors.

NewROmancer

if you are using GLUT 3.7.3

at the top of your program outside of main
add #define GLUT_DISABLE_ATEXIT_HACK