Back to index

kdeartwork  4.3.2
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
Wave Class Reference

#include <wave.h>

List of all members.

Public Member Functions

 Wave (QWidget *parent=0)
 ~Wave ()

Protected Member Functions

void paintGL ()
 paint the GL view
void resizeGL (int w, int h)
 resize the gl view
void initializeGL ()
 setup the GL environment

Private Member Functions

bool LoadGLTextures ()

Private Attributes

GLUnurbsObj * pNurb
GLint nNumPoints
int index
GLuint texture [1]
QImage tex

Detailed Description

Definition at line 32 of file wave.h.


Constructor & Destructor Documentation

Wave::Wave ( QWidget *  parent = 0)

Definition at line 168 of file wave.cpp.

                             : QGLWidget (parent)
{
       pNurb = 0;

       nNumPoints = 4;
       index = 0;
}

Definition at line 176 of file wave.cpp.

{
       glDeleteTextures( 1, &texture[0] );
       gluDeleteNurbsRenderer(pNurb);
}

Member Function Documentation

void Wave::initializeGL ( void  ) [protected]

setup the GL environment

Definition at line 183 of file wave.cpp.

{

       kDebug() << "InitGL";

       /* Load in the texture */
       if ( !LoadGLTextures( ) )
              exit(0);

       /* Enable Texture Mapping ( NEW ) */
       glEnable( GL_TEXTURE_2D );

       /* Enable smooth shading */
       glShadeModel( GL_SMOOTH );
       // Light values and coordinates
       GLfloat  specular[] = { 0.7f, 0.0f, 0.0f, 1.0f};
       GLfloat  shine[] = { 75.0f };

       glClearColor(0.0f, 0.0f, 0.0f, 0.0f );

       glEnable(GL_LIGHTING);
       glEnable(GL_LIGHT0);

       glEnable(GL_COLOR_MATERIAL);

       glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
       glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
       glMaterialfv(GL_FRONT, GL_SHININESS, shine);

       glEnable(GL_AUTO_NORMAL);


       pNurb = gluNewNurbsRenderer();

       gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f);
              // Uncomment the next line and comment the one following to produce a
              // wire frame mesh.
       //gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
       gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, (GLfloat)GLU_FILL);
       glEnable(GL_MAP2_TEXTURE_COORD_3);
       glEnable(GL_MAP2_VERTEX_3);
       glEnable(GL_BLEND);

}

Here is the call graph for this function:

bool Wave::LoadGLTextures ( ) [private]

Definition at line 307 of file wave.cpp.

{
    /* Status indicator */
    bool Status = true;

       QImage buf; // = QPixmap::grabWindow ( 0 ).convertToImage();
   kDebug() << "Loading: " << KStandardDirs::locate("data", "kscreensaver/image.png");
 if (buf.load( KStandardDirs::locate("data", "kscreensaver/image.png") ) )

        {
                tex = convertToGLFormat(buf);  // flipped 32bit RGBA
                kDebug() << "Texture loaded: " << tex.numBytes ();
        }
        else
        {
                QImage dummy( 64, 64, QImage::Format_RGB32 );
                dummy.fill( Qt::white );
                buf = dummy;
                tex = convertToGLFormat( buf );
        }
            /* Set the status to true */
            //Status = true;
       glGenTextures(1, &texture[0]);   /* create three textures */
       glBindTexture(GL_TEXTURE_2D, texture[0]);
       /* use linear filtering */
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       /* actually generate the texture */
       glTexImage2D(GL_TEXTURE_2D, 0, 4, tex.width(), tex.height(), 0,
       GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());
       kDebug() << "Texture Loaded: " << tex.width() << "," << tex.height();


    return Status;
}

Here is the caller graph for this function:

void Wave::paintGL ( void  ) [protected]

paint the GL view

Definition at line 252 of file wave.cpp.

{

       float ctrlPoints[4][4][3];

       index++;
       float Z[16];
       for( int i = 0; i < 16; i++)
       {
              Z[i] = 3.0 * sin(16*(3.141592654 * 2.0f) * (index+(i))/360);
       }

//     kDebug() << "-----";
       int counter =15;
       for( int i = 0; i < 4; i++)
              for( int j = 0; j < 4;j++)
              {
                     ctrlPoints[i][j][0] = float((5*i)-10);
                     ctrlPoints[i][j][1] = float((3*j)-6);
                     ctrlPoints[i][j][2] = Z[counter--];
//                   kDebug() << Z[counter];
              }
       // Knot sequence for the NURB
       float knots[8] = { 0, 0, 0, 0,  1, 1, 1, 1 };
        // Draw in Blu
        //glColor3ub(0,0,220);

        // Clear the window with current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Save the modelview matrix stack
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();

        // Rotate the mesh around to make it easier to see
        glRotatef(index/2, 1.0f,0.0f,0.0f);
       glRotatef(index/5, 0.0f,1.0f,0.0f);
       glRotatef(index/6, 0.0f,0.0f,1.0f);

        // Render the NURB
       gluBeginSurface( pNurb );
              gluNurbsSurface( pNurb, 8, knots, 8, knots,
              4*3, 3, &ctrlPoints[0][0][0], 4, 4, GL_MAP2_TEXTURE_COORD_3);
              //gluNurbsSurface( pNurb, 8, knots, 8, knots,
              //4*3, 3, &ctrlPoints[0][0][0], 4, 4, GL_MAP2_NORMAL );
              gluNurbsSurface( pNurb, 8, knots, 8, knots,
              4*3, 3, &ctrlPoints[0][0][0], 4, 4, GL_MAP2_VERTEX_3 );
       gluEndSurface( pNurb );

        // Restore the modelview matrix
        glPopMatrix();

       glFlush();
}
void Wave::resizeGL ( int  w,
int  h 
) [protected]

resize the gl view

Definition at line 228 of file wave.cpp.

{
       kDebug() << "ResizeGL " << w << "," <<h;
        // Prevent a divide by zero
        if(h == 0)
                h = 1;

        // Set Viewport to window dimensions
    glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        // Perspective view
        gluPerspective (45.0f, (GLdouble)w/(GLdouble)h, 1.0, 40.0f);

        // Modelview matrix reset
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        // Viewing transformation, position for better view
    glTranslatef (0.0f, 0.0f, -20.0f);

}

Member Data Documentation

int Wave::index [private]

Definition at line 55 of file wave.h.

GLint Wave::nNumPoints [private]

Definition at line 52 of file wave.h.

GLUnurbsObj* Wave::pNurb [private]

Definition at line 51 of file wave.h.

QImage Wave::tex [private]

Definition at line 58 of file wave.h.

GLuint Wave::texture[1] [private]

Definition at line 57 of file wave.h.


The documentation for this class was generated from the following files: