PLEASE help

I’m using Borland C++ 4.52.
I’m trying to make the following program work:

// Includes

#include <windows.h>
#include <GL/gl.h>

// Function Declarations

LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam );
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC );
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC );

// WinMain

int WINAPI
WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow )
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;

// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = “GLSample”;
RegisterClass( &wc );

// create main window
hWnd =
ateWindow(
“GLSample”, “OpenGL Sample”,
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL, hInstance, NULL );

// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );

// program main loop
while ( !bQuit ) {

// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {

  // handle or dispatch messages
  if ( msg.message == WM_QUIT ) {
    bQuit = TRUE;
  } else {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
  }

} else {

  // OpenGL animation code goes here

  glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  glClear( GL_COLOR_BUFFER_BIT );

  glPushMatrix();
  glRotatef( theta, 0.0f, 0.0f, 1.0f );
  glBegin( GL_TRIANGLES );
  glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
  glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
  glColor3f( 0.0f, 0.0f, 1.0f )

; glVertex2f( -0.87f, -0.5f );
glEnd();
glPopMatrix();

  SwapBuffers( hDC );

  theta += 1.0f;

}

}

// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );

// destroy the window explicitly
DestroyWindow( hWnd );

return msg.wParam;

}

// Window Procedure

LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam )
{

switch ( message ) {

case WM_CREATE:
return 0;

case WM_CLOSE:
PostQuitMessage( 0 );
return 0;

case WM_DESTROY:
return 0;

case WM_KEYDOWN:
switch ( wParam ) {

case VK_ESCAPE:
  PostQuitMessage( 0 );
  return 0;

}
return 0;

default:
return DefWindowProc( hWnd,
message, wParam, lParam );

}

}

// Enable OpenGL

VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

// get the device context (DC)
*hDC = GetDC( hWnd );

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, iFormat, &pfd );

// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}

// Disable OpenGL

VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}

Why does it have these errors???

Compiling GLSAMPLE.CPP:
Error …\BC45\INCLUDE\GL\GL.H 2301: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2303: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2303: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2305: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2305: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2307: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2307: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2309: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2309: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2311: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2311: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2313: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2313: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2315: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2315: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2317: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2317: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2319: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2319: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2321: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2321: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2323: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2323: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2325: Variable ‘WINGDIAPI’ is
initialized more than once
Error …\BC45\INCLUDE\GL\GL.H 2325: Declaration syntax error
Error …\BC45\INCLUDE\GL\GL.H 2325: Too many error or warning messages

Greg Holland

It happened to me, identical, but with Borland C++Builder.
I think that gl.h assumes some definitions of window.h that don’t exists or are different in borland headers. I solved the problem restoring old opengl headers that came up directly with BC++B, and it worked.
If your compiler has not these headers in default include dirs, try in the borland site…

Hi,

hmm. already declared identifies means… you’ve already declared the identifiers. that’s bad.

I know naught about ye olde windows programming, but i’d suggest you axe the #inc<windows> from your main.c file, because I’m guessing that your version of gl.h is foolishly already including it. incentially, if you did this in your main file:

#define GOAT
#define GOAT

you’ll get the same error (because by the time you get to the second #define, GOAT is already declared. funny, that). Try it! Fun for all the family.

cheers,
John

except, now that i look at the error messages and their stunning similarity, I wonder…

maybe axeing windows.h isn’t such a good idea after all. maybe axe your gl.h file? Maybe axe your compiler? Your cat? Your family? Your Gl seems to REALLY want to redfine the SAME thing over and OOOOOVER again. so, maybe i’m just confused.

cheers
John

Let’s think ‘compiler-way’…
I suppose that bcc misunderstands some earlier declaration or misses some ‘}’.
For example, if in a strange way it does not read the line
#define WINGDIAPI whateveritcanbe
then it reaches a function declared as (I don’t remember exactly):
int WINGDIAPI glEnableforexample(argsargs);
Now the compiler looks at it like the declaration of a int variable named WINGDIAPI!!
Probably WINGDIAPI should be defined as a function qualifier such as __pascal, or __fastcall ecc…
Then you can understand this message:
Error …\BC45\INCLUDE\GL\GL.H 2301: Declaration syntax error
With this error the compiler wants to say that after ‘int WINGDIAPI’ there’s something wrong, exactly the name of the function.
So it follows that:
Variable ‘WINGDIAPI’ is
initialized more than once

means that the compiler reached a new line declaring a new opengl function, but it still consider it a variable declaration.
On the same line, there is another error, similar to the first we looked at (line numbers confirm that).

What’s the solution?
Solution 1: the one I wrote in the first post: look at borland version of the headers
Solution 2: try to define WINGDIAPI as empty (#define WINGDIAPI) before including gl.h

Bye!
(English is not my mother tongue, hope you understood)

I would suggest looking at line 2301 of gl.h to see what exactly went wrong. As I think Teofuzz is on the right track. More than likely there are functions being declared using WINGDIAPI and are ok. But at or near line 2301, something has gone awry.

I don’t have the same headers you got right here, but I suggest the following:

  1. Go to line 2301 in gl.h
  2. If this line contains something like “#define WINGDIAPI …” then insert a “#undef WINGDIAPI” above.
  3. If this line contains a function prototype insert the following right above:
    #undef WINGDIAPI
    #define WINGDIAPI DECLSPEC_IMPORT

That’s all I got for you without actually seeing your gl.h

[This message has been edited by Inquisitor (edited 10-12-2000).]

When I had this problem it was because I wasn’t including <windows.h>. (put it before your ogl includes.)