Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Cpw - Does it calculate normals on primitives

  1. #1
    Intern Contributor
    Join Date
    Dec 2001
    Posts
    93

    Cpw - Does it calculate normals on primitives

    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

    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;
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: Cpw - Does it calculate normals on primitives

    which redbook example are your trying so I can take a look at it?

    FYI the cube code is the same code glut uses:

    /* Silicon Graphics function */

    void cpw_primitives_3d_drawbox( GLfloat size, GLenum type )
    {
    GLfloat v[8][3];
    GLint i;

    v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
    v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
    v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
    v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
    v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
    v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;

    for (i = 5; i >= 0; i--) {
    glBegin(type);
    glNormal3fv(&n[i][0]);
    glTexCoord2d(0.0, 0.0);
    glVertex3fv(&v[faces[i][0]][0]);
    glTexCoord2d(1.0, 0.0);
    glVertex3fv(&v[faces[i][1]][0]);
    glTexCoord2d(1.0, 1.0);
    glVertex3fv(&v[faces[i][2]][0]);
    glTexCoord2d(0.0, 1.0);
    glVertex3fv(&v[faces[i][3]][0]);
    glEnd();
    }
    }

    Regards,
    Jim
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •