jpummill
02-27-2002, 01:15 PM
Hi All,
I am trying a example out the the OpenGL Redbook (chapter 5 - Lighting). It works in Glut but I am having problems when using it with Cpw. Currently my only guess is that the primitives in Cpw do not calculate normals. Of course I could have just screwed up while writing the program also http://www.opengl.org/discussion_boards/ubb/smile.gif
Here is my code if anyone has time to look through it:
/************************************************** *************/
/* NAME: cpw_lighting.cpp */
/* DATE: 02/26/2002 */
/* AUTHOR: John Pummill */
/************************************************** *************/
/************************************************** **/
/* Basic Win32 Template */
/************************************************** **/
#define CPWDLL_EXTERN /* link to the dll's stub */
#include <cpw.h>
/* handy window characteristics holder */
static CpwWindowInfo windowInfo = { 0,100,100,300,300 }; /* id,posx,posy,w,h */
/************************************************** **/
/* OpenGL 3D Matrix Setup */
/************************************************** **/
void set3DMatrix( void )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
if ( windowInfo.width <= windowInfo.height )
glOrtho ( -1.5, 1.5, -1.5*((float)windowInfo.height)/((float)windowInfo.width), 1.5*((float)windowInfo.height)/((float)windowInfo.width), -10.0, 10.0 );
else
glOrtho ( -1.5*((float)windowInfo.width)/((float)windowInfo.height), 1.5*((float)windowInfo.width)/((float)windowInfo.height), -1.5, 1.5, -10.0, 10.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
/************************************************** **/
/* Draw Window One */
/************************************************** **/
void drawWindowOne( pCpw cpw )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
set3DMatrix();
/* draw something in the window with OpenGL */
glLoadIdentity();
glTranslatef(0.0f,0.0f, 0.0f);
glRotatef(-60.0f, 1.0f, 0.5f, 0.0f);
cpwSetPrimitiveOpt( cpw, CPW_PRIMOPT_SIZE, 1.0f );
cpwDrawPrimitive( cpw, CPW_PRIM_3D_SOLIDCUBE );
}
/************************************************** **/
/* Window Draw Event callback */
/************************************************** **/
void draw( pCpw cpw, uint_32 winid )
{
drawWindowOne( cpw );
cpwSwapWindowBuffers( cpw, winid );
}
/************************************************** **/
/* Window Create / Destroy Event callback */
/************************************************** **/
void window( pCpw cpw, uint_32 winid, bool flag )
{
/* creation event */
if ( flag == true ) {
GLfloat mat_specular[] = { 1.0, 1.0, 0.0, 1.0 };
GLfloat mat_shininess[] = { 70.0 };
GLfloat light_position[] = { -1.0, 1.0, 1.0, 0.0 };
glShadeModel( GL_SMOOTH );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_BACK, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
return;
}
/* window close event */
if ( flag == false ) {
cpwDestroyWindow( cpw, winid );
return;
}
}
/************************************************** **/
/* Window Resize Event callback */
/************************************************** **/
void reshape( pCpw cpw, uint_32 winid, uint_32 width, uint_32 height )
{
if ( height == 0 ) { height = 1; }
if ( width == 0 ) { width = 1; }
windowInfo.width = width;
windowInfo.height = height;
printf("Resize Event: width = %d, height = %d\n", width, height); /* JP - Print Vars */
set3DMatrix();
glViewport( 0, 0, width, height );
}
/************************************************** **/
/* Main */
/************************************************** **/
#ifdef _WINDOWS
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
#elif _CONSOLE
int main(int argc, char* argv[])
#endif
{
pCpw cpw = null;
/************************************************** **/
/* Init */
/************************************************** **/
cpwInitContext( &cpw );
/************************************************** **/
/* Creaing Windows */
/************************************************** **/
windowInfo.id =
cpwCreateWindowEx( cpw, "Basic Template", windowInfo.x, windowInfo.y,
windowInfo.width, windowInfo.height );
/************************************************** **/
/* Event Callbacks */
/************************************************** **/
cpwCreateCallback( cpw, window );
cpwDisplayCallback( cpw, draw );
cpwReshapeCallback( cpw, reshape );
/************************************************** **/
/* MainLoop */
/************************************************** **/
cpwMainLoop( cpw );
/************************************************** **/
/* Exit and Free */
/************************************************** **/
cpwFreeContext( &cpw );
return 0;
}
I am trying a example out the the OpenGL Redbook (chapter 5 - Lighting). It works in Glut but I am having problems when using it with Cpw. Currently my only guess is that the primitives in Cpw do not calculate normals. Of course I could have just screwed up while writing the program also http://www.opengl.org/discussion_boards/ubb/smile.gif
Here is my code if anyone has time to look through it:
/************************************************** *************/
/* NAME: cpw_lighting.cpp */
/* DATE: 02/26/2002 */
/* AUTHOR: John Pummill */
/************************************************** *************/
/************************************************** **/
/* Basic Win32 Template */
/************************************************** **/
#define CPWDLL_EXTERN /* link to the dll's stub */
#include <cpw.h>
/* handy window characteristics holder */
static CpwWindowInfo windowInfo = { 0,100,100,300,300 }; /* id,posx,posy,w,h */
/************************************************** **/
/* OpenGL 3D Matrix Setup */
/************************************************** **/
void set3DMatrix( void )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
if ( windowInfo.width <= windowInfo.height )
glOrtho ( -1.5, 1.5, -1.5*((float)windowInfo.height)/((float)windowInfo.width), 1.5*((float)windowInfo.height)/((float)windowInfo.width), -10.0, 10.0 );
else
glOrtho ( -1.5*((float)windowInfo.width)/((float)windowInfo.height), 1.5*((float)windowInfo.width)/((float)windowInfo.height), -1.5, 1.5, -10.0, 10.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
/************************************************** **/
/* Draw Window One */
/************************************************** **/
void drawWindowOne( pCpw cpw )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
set3DMatrix();
/* draw something in the window with OpenGL */
glLoadIdentity();
glTranslatef(0.0f,0.0f, 0.0f);
glRotatef(-60.0f, 1.0f, 0.5f, 0.0f);
cpwSetPrimitiveOpt( cpw, CPW_PRIMOPT_SIZE, 1.0f );
cpwDrawPrimitive( cpw, CPW_PRIM_3D_SOLIDCUBE );
}
/************************************************** **/
/* Window Draw Event callback */
/************************************************** **/
void draw( pCpw cpw, uint_32 winid )
{
drawWindowOne( cpw );
cpwSwapWindowBuffers( cpw, winid );
}
/************************************************** **/
/* Window Create / Destroy Event callback */
/************************************************** **/
void window( pCpw cpw, uint_32 winid, bool flag )
{
/* creation event */
if ( flag == true ) {
GLfloat mat_specular[] = { 1.0, 1.0, 0.0, 1.0 };
GLfloat mat_shininess[] = { 70.0 };
GLfloat light_position[] = { -1.0, 1.0, 1.0, 0.0 };
glShadeModel( GL_SMOOTH );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_BACK, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
return;
}
/* window close event */
if ( flag == false ) {
cpwDestroyWindow( cpw, winid );
return;
}
}
/************************************************** **/
/* Window Resize Event callback */
/************************************************** **/
void reshape( pCpw cpw, uint_32 winid, uint_32 width, uint_32 height )
{
if ( height == 0 ) { height = 1; }
if ( width == 0 ) { width = 1; }
windowInfo.width = width;
windowInfo.height = height;
printf("Resize Event: width = %d, height = %d\n", width, height); /* JP - Print Vars */
set3DMatrix();
glViewport( 0, 0, width, height );
}
/************************************************** **/
/* Main */
/************************************************** **/
#ifdef _WINDOWS
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
#elif _CONSOLE
int main(int argc, char* argv[])
#endif
{
pCpw cpw = null;
/************************************************** **/
/* Init */
/************************************************** **/
cpwInitContext( &cpw );
/************************************************** **/
/* Creaing Windows */
/************************************************** **/
windowInfo.id =
cpwCreateWindowEx( cpw, "Basic Template", windowInfo.x, windowInfo.y,
windowInfo.width, windowInfo.height );
/************************************************** **/
/* Event Callbacks */
/************************************************** **/
cpwCreateCallback( cpw, window );
cpwDisplayCallback( cpw, draw );
cpwReshapeCallback( cpw, reshape );
/************************************************** **/
/* MainLoop */
/************************************************** **/
cpwMainLoop( cpw );
/************************************************** **/
/* Exit and Free */
/************************************************** **/
cpwFreeContext( &cpw );
return 0;
}