OpenGL, Watcom C and C++ (Yet another... ;-)
- From: Rene <invalid@xxxxxxxxxxx>
- Date: Thu, 14 Jun 2007 20:40:57 +0200
Hello to everybody and good evening/night/morning/afternoon,
I am new to OpenGL. I managed to get my hands on a second hand copy of "Computer Graphics using OpenGL" by F.S. Hill jr, second print (for only 15 euro's, isn't that a bargain) and am very enthousiastic about the capabilities of this language. I have not much experience with C or C++ but know a little bit about it. I downloaded and installed Open Watcom (current version) and GLUT 3.7 and installed the files according to the instructions on http://www.di.unipi.it/~nids/docs/watcom_glut_sdl.shtml. The book is a bit vague about the installing of the programs, it more or less assumes that one knows how to get everything going. Before deciding to ask You for help, I have spent many many hours of searching on the web because I got so many errors and not having experience with a modern compiler like this one (having done programming only in DOS), it baffled me and gave me many headaches. What I would really like is just get the thing going so I can type in the examples of the book and alter them when they are working, that seems great fun to me. So if someone could help me to get started, I would be very grateful!
However, finally I found http://www.trajectorylabs.com/getting_started_with_opengl_glut.html. No need to open that page, the source code listed there is here (it is for Pelles C but I do not think there is something Pelles-specific in it):
//---------------------------------------------------------------------
// Getting Started with OpenGL GLUT
// A Very Simple OpenGL Example
//
// Draws a simple window with a rectangle in it
//---------------------------------------------------------------------
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
void init(void);
void display(void);
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("My First OpenGL Application");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRectf(-5.0, 5.0, 5.0, -5.0);
glutSwapBuffers();
}
//---------------------------------------------------------------------
This compiles fine in Watcom when I save it as a .c file (and give the -5s switch to the compiler) and the resulting .exe runs fine as well. The problem is that the writer of my book will be using oo code later on in the book so I need to be able to program in C++. When saving the code as .cpp and compiling it as C++ code (with the -5s switch) through the IDE, I get the following output in the IDE window:
cd C:\WATCOM\Projects
wmake -f C:\WATCOM\Projects\oglcpp.mk -h -e -a C:\WATCOM\Projects\Pelles.obj
wpp386 Pelles.cpp -i=C:\WATCOM\h;C:\WATCOM\h\nt -w4 -e25 -zq -od -d2 -5s -bt=nt -mf -xs -xr
C:\WATCOM\h\nt\Gl\glut.h(146): Error! E867: col(38) conflict with a previous using-decl 'exit'
C:\WATCOM\h\nt\Gl\glut.h(146): Note! N393: col(38) included from Pelles.cpp(10)
C:\WATCOM\h\stdlib.h(48): Note! N392: col(10) definition: 'void watcall exit( int )'
C:\WATCOM\h\nt\Gl\glut.h(486): Warning! W601: col(102) converted function type has different #pragma from original function type
C:\WATCOM\h\nt\Gl\glut.h(503): Warning! W601: col(112) converted function type has different #pragma from original function type
C:\WATCOM\h\nt\Gl\glut.h(549): Warning! W601: col(120) converted function type has different #pragma from original function type
Pelles.cpp(27): Warning! W014: col(2) no reference to symbol 'glutCreateMenu_ATEXIT_HACK'
C:\WATCOM\h\nt\Gl\glut.h(549): Note! N392: col(21) definition: 'int stdcall glutCreateMenu_ATEXIT_HACK( void (* )( int ))'
Error(E42): Last command making (C:\WATCOM\Projects\Pelles.obj) returned a bad status
Error(E02): Make execution terminated
Execution complete
When compiling it through the command line I get:
C:\WATCOM\Projects>wpp386 -5s pelles.cpp
Open Watcom C++32 Optimizing Compiler Version 1.6
Portions Copyright (c) 1989-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
C:\WATCOM\H\NT\Gl\glut.h(146): Error! E867: col(38) conflict with a previous using-decl 'exit'
C:\WATCOM\H\NT\Gl\glut.h(146): Note! N393: col(38) included from pelles.cpp(10)
C:\WATCOM\H\stdlib.h(48): Note! N392: col(10) definition: 'void watcall exit( int )'
C:\WATCOM\H\NT\Gl\glut.h(486): Warning! W601: col(102) converted function type has different #pragma from original function type
C:\WATCOM\H\NT\Gl\glut.h(503): Warning! W601: col(112) converted function type has different #pragma from original function type
C:\WATCOM\H\NT\Gl\glut.h(549): Warning! W601: col(120) converted function type has different #pragma from original function type
pelles.cpp: 44 lines, included 46799, 3 warnings, 1 error
I would very much appreciate it if someone could tell me what I should adjust to the source (especially the "initialisation" part) so that I will be able to concentrate on the graphic part. I asked this question a couple of days ago in a Watcom group but there has been no reply (first I thought it would be a special Watcom problem but after seeing that compiling the code as plain C code worked, I was not so sure anymore) so now all my hopes are on You :-) (if I do get another reply in the other group, I will let You know and also the other way around).
Oh, one little question more if that is OK with You (if not OK please skip the rest of this paragraph). I have searched what this #pragma thing means but I can't find a satisfying answer. I do not think the true meaning of it will be of great importance to me in the near future (first I just want to copy the source code from the book, if I find I like it I want to sink my teeth deeper in C++ fundamentals) but I am a bit curious about it anyway.
I really hope someone can help me get started. The number of hours I already spent on it can't be counted on the fingers of two hands and they were completely fruitless... So many thanks in advance (and many thanks for reading this long piece of text as well)!
If You need more information or want me to try something, please let me know.
Yours sincerely,
Rene
P.S. Because of my job I do not have the opportunity to sit at my computer very often and I can never predict when that will be, so if my reply takes a while that is not because I am not interested.
P.P.S. Please forgive me language errors, English is not my mother tongue.
.
- Follow-Ups:
- Re: OpenGL, Watcom C and C++ (Yet another... ;-)
- From: fungus
- Re: OpenGL, Watcom C and C++ (Yet another... ;-)
- Prev by Date: Re: Mac OSX - Picking - Best way
- Next by Date: Re: OpenGL, Watcom C and C++ (Yet another... ;-)
- Previous by thread: GPU and OpenGL
- Next by thread: Re: OpenGL, Watcom C and C++ (Yet another... ;-)
- Index(es):
Relevant Pages
|