PDA

View Full Version : Errors of Porting to OpenGL 1.2 for Managed C++ coding in VC++.NET (2002)



Scott Chang
08-04-2003, 05:57 AM
Hi all,
I tried to use Managed C++ coding of VC++.NET (2002)and
OpenGL version 1.2 to draw a hexagon shape of benzene.
My OpenGLdrawBenzene.cpp is the following:
// This is the main project file for VC++ application
project
// generated using an Application Wizard.

#include "stdafx.h"
#include
#include
#include // OpenGL Graphics Utility
Library
#using
#include

using namespace System;

// These variables set the dimensions of the
rectanglar region we wish to view.
const double Xmin = 0.0, Xmax = 3.0;
const double Ymin = 0.0, Ymax = 3.0;

// Clear the rendering window
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);

// Set drawing color to white
glColor3f( 1.0, 1.0, 1.0 );
// Draw six points on xy plane with z=0.0
glBegin(GL_POINTS);
glVertex3f( 0.0, 0.0, 0.0 );
glVertex3f( 0.9, 1.0, 0.0 );
glVertex3f( 1.9, 1.0, 0.0 );
glVertex3f( 2.8, 0.0, 0.0 );
glVertex3f( 1.9,-1.0, 0.0 );
glVertex3f( 0.9,-1.0, 0.0 );
glEnd();
// Flush the pipeline. (Not usually necessary.)
glFlush();
}
// Initialize OpenGL's rendering modes
void initRendering()
{
// Called when the window is resized
// w, h - width and height of the window in
pixels.
void resizeWindow(int w, int h)
{
double scale, center;
double windowXmin, windowXmax, windowYmin,
windowYmax;

// Define the portion of the window used for OpenGL
rendering.
glViewport( 0, 0, w, h ); // View port uses
whole
window

// Set up the projection view matrix: orthographic
projection
// Determine the min and max values for x and y
that
should appear in the window.
// The complication is that the aspect ratio of the
window may not match the
// aspect ratio of the scene we want
to view.
w = (w==0) ? 1 : w;
h = (h==0) ? 1 : h;
if ( (Xmax-Xmin)/w < (Ymax-Ymin)/h ) {
scale = ((Ymax-Ymin)/h)/((Xmax-Xmin)/w);
center = (Xmax+Xmin)/2;
windowXmin = center - (center-Xmin)*scale;
windowXmax = center + (Xmax-center)*scale;
windowYmin = Ymin;
windowYmax = Ymax;
}
else {
scale = ((Xmax-Xmin)/w)/((Ymax-Ymin)/h);
center = (Ymax+Ymin)/2;
windowYmin = center - (center-Ymin)*scale;
windowYmax = center + (Ymax-center)*scale;
windowXmin = Xmin;
windowXmax = Xmax;
}

// Now that we know the max & min values for x & y
that should be visible in the window,
// we set up the orthographic
projection.
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( windowXmin, windowXmax, windowYmin,
windowYmax, -1, 1 );

}


// This is the entry point for this application
int _tmain(int argc, char** argv)
{
// TODO: Please replace the sample code below with
your own.
Console::WriteLine(S"OpenGLdrawBenzene");

///////////int main( int argc, char** argv )

glutInit(&argc,argv);

// The image is not animated so single buffering is
OK.
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB |
GLUT_DEPTH );

// Window position (from top corner), and size
(width
and hieght)
glutInitWindowPosition( 20, 60 );
glutInitWindowSize( 360, 360 );
glutCreateWindow( "SimpleDraw - Press space bar to
toggle images" );

// Initialize OpenGL as we like it..
initRendering();

// Set up callback functions for key presses
glutKeyboardFunc( myKeyboardFunc );
// Handles
"normal" ascii symbols
// glutSpecialFunc( mySpecialKeyFunc ); //
Handles
"special" keyboard keys

// Set up the callback function for resizing
windows
glutReshapeFunc( resizeWindow );

// Call this for background processing
// glutIdleFunc( myIdleFunction );

// call this whenever window needs redrawing
glutDisplayFunc( drawScene );

fprintf(stdout, "Press space bar to toggle images;
escape button to quit.\n");

// Start the main loop. glutMainLoop never
returns.
glutMainLoop( );
return 0;
}
///////////////////////////////////////
When I built it, I got many errors:
------ Build started: Project: OpenGLdrawBenzene,
Configuration: Debug Win32 ------

Compiling...
OpenGLdrawBenzene.cpp
OpenGLdrawBenzene.cpp(18) : error C2501: 'glClear' :
missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(18) : error C2365: 'glClear' :
redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1162) : see
declaration of 'glClear'
OpenGLdrawBenzene.cpp(21) : error C2501: 'glColor3f' :
missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(21) : error C2365: 'glColor3f' :
redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1173) : see
declaration of 'glColor3f'
OpenGLdrawBenzene.cpp(21) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(23) : error C2501: 'glBegin' :
missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(23) : error C2365: 'glBegin' :
redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1156) : see
declaration of 'glBegin'
OpenGLdrawBenzene.cpp(24) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(24) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(24) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(25) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(25) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(25) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(26) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(26) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(26) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(27) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(27) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(27) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(28) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(28) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(28) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(29) : error C2501: 'glVertex3f'
: missing storage-class or type specifiers
OpenGLdrawBenzene.cpp(29) : error C2365: 'glVertex3f'
: redefinition; previous definition was a 'function'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1472) : see
declaration of 'glVertex3f'
OpenGLdrawBenzene.cpp(29) : error C2078: too many
initializers
OpenGLdrawBenzene.cpp(30) : error C2556: 'int
glEnd(void)' : overloaded function differs only by
return type from 'void glEnd(void)'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1226) : see
declaration of 'glEnd'
OpenGLdrawBenzene.cpp(30) : error C2373: 'glEnd' :
redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1226) : see
declaration of 'glEnd'
OpenGLdrawBenzene.cpp(32) : error C2556: 'int
glFlush(void)' : overloaded function differs only by
return type from 'void glFlush(void)'
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1242) : see
declaration of 'glFlush'
OpenGLdrawBenzene.cpp(32) : error C2373: 'glFlush' :
redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\gl\GL.h(1242) : see
declaration of 'glFlush'
OpenGLdrawBenzene.cpp(33) : error C2059: syntax error
: '}'
OpenGLdrawBenzene.cpp(33) : error C2143: syntax error
: missing ';' before '}'
OpenGLdrawBenzene.cpp(33) : error C2059: syntax error
: '}'
OpenGLdrawBenzene.cpp(36) : error C2143: syntax error
: missing ';' before '{'
OpenGLdrawBenzene.cpp(36) : error C2447: '{' : missing
function header (old-style formal list?)
OpenGLdrawBenzene.cpp(119) : fatal error C1004:
unexpected end of file found

Build log was saved at "file://c:\Documents and
Settings\default\My
Documents\Programming\OpenGLdrawBenzene\Debug\Buil dLog.htm"
OpenGLdrawBenzene - 35 error(s), 0 warning(s)

---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped
///////////////////////////////////////////////
Please kindly tell me what caused the first error in
Line 18 of this .cpp

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

and how to cure it. If you can help me more in
solving the rest of the errors, I will be greatly
appreciated.

Thanks in advance,
Scott Chang

jwatte
08-04-2003, 05:59 AM
Details of what error messages from your compiler mean, and what you can do to fix them, might be available in the documentation that came with your compiler.

Scott Chang
08-04-2003, 09:18 AM
I really do not know what storage-class is and explanation for the error C2501 in the compiler do not ring a bell to me. Please be specific and give me more details for solving the error.

Thanks,
Scott Chang

Korval
08-04-2003, 10:09 AM
I tried to use Managed C++ coding of VC++.NET (2002)and OpenGL version 1.2 to draw a hexagon shape of benzene.

Managed C++ has limitations placed on it, compared to real C++. I don't know what those limitations are, but it is not unreasonable to believe that GL violates them.


#include // OpenGL Graphics Utility Library

What is this, specifically? Your errors seem like you're not really including the appropriate OpenGL headers.

roffe
08-04-2003, 10:10 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/c2501.asp

Compiler errors have nothing to do with OpenGL coding. I suggest you post these question in a VC or .NET forum in the future.