None.gifGLvoid COpenGLDemoView::glPrint(GLint x, GLint y, char *stringint set)                    // Custom GL "Print" Routine
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif     
if (set>1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
set=1;
ExpandedSubBlockEnd.gif    }

InBlock.gif    glBindTexture(GL_TEXTURE_2D, texture[
0]);            // Select Our Font Texture
InBlock.gif
    glDisable(GL_DEPTH_TEST);                            // Disables Depth Testing
InBlock.gif
    glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
InBlock.gif
    glPushMatrix();                                        // Store The Projection Matrix
InBlock.gif
    glLoadIdentity();                                    // Reset The Projection Matrix
InBlock.gif
    glOrtho(0,640,0,480,-1,1);                            // Set Up An Ortho Screen
InBlock.gif
    glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
InBlock.gif
    glPushMatrix();                                        // Store The Modelview Matrix
InBlock.gif
    glLoadIdentity();                                    // Reset The Modelview Matrix
InBlock.gif
    glTranslated(x,y,0);                                // Position The Text (0,0 - Bottom Left)
InBlock.gif
    glListBase(base-32+(128*set));                        // Choose The Font Set (0 or 1)
InBlock.gif
    glCallLists(strlen(string),GL_UNSIGNED_BYTE,string);// Write The Text To The Screen
InBlock.gif
    glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
InBlock.gif
    glPopMatrix();                                        // Restore The Old Projection Matrix
InBlock.gif
    glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
InBlock.gif
    glPopMatrix();                                        // Restore The Old Projection Matrix
InBlock.gif
    glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing                                    // Pops The Display List Bits
ExpandedBlockEnd.gif
}

None.gifGLvoid COpenGLDemoView::BuildFont(GLvoid)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
float    cx;                                            // Holds Our X Character Coord
InBlock.gif
    float    cy;                                            // Holds Our Y Character Coord
InBlock.gif

InBlock.gif    
base=glGenLists(256);                                // Creating 256 Display Lists
InBlock.gif
    glBindTexture(GL_TEXTURE_2D, texture[0]);            // Select Our Font Texture
InBlock.gif
    for (int i =0; i<256; i++)                        // Loop Through All 256 Lists
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        cx
=float(i%16)/16.0f;                        // X Position Of Current Character
InBlock.gif
        cy=float(i/16)/16.0f;                        // Y Position Of Current Character
InBlock.gif

InBlock.gif        glNewList(
base+i,GL_COMPILE);                // Start Building A List
InBlock.gif
            glBegin(GL_QUADS);                            // Use A Quad For Each Character
InBlock.gif
                glTexCoord2f(cx,1-cy-0.0625f);            // Texture Coord (Bottom Left)
InBlock.gif
                glVertex2i(0,0);                        // Vertex Coord (Bottom Left)
InBlock.gif
                glTexCoord2f(cx+0.0625f,1-cy-0.0625f);    // Texture Coord (Bottom Right)
InBlock.gif
                glVertex2i(16,0);                        // Vertex Coord (Bottom Right)
InBlock.gif
                glTexCoord2f(cx+0.0625f,1-cy);            // Texture Coord (Top Right)
InBlock.gif
                glVertex2i(16,16);                        // Vertex Coord (Top Right)
InBlock.gif
                glTexCoord2f(cx,1-cy);                    // Texture Coord (Top Left)
InBlock.gif
                glVertex2i(0,16);                        // Vertex Coord (Top Left)
InBlock.gif
            glEnd();                                    // Done Building Our Quad (Character)
InBlock.gif
            glTranslated(10,0,0);                        // Move To The Right Of The Character
InBlock.gif
        glEndList();                                    // Done Building The Display List
ExpandedSubBlockEnd.gif
    }
                                                    // Loop Until All 256 Are Built
ExpandedBlockEnd.gif
}

None.gif
None.gif
int COpenGLDemoView::DrawGLScene()                                   
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{// Here's Where We Do All The Drawing
InBlock.gif
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
InBlock.gif
    glLoadIdentity();                                    // Reset The Modelview Matrix
InBlock.gif
    glBindTexture(GL_TEXTURE_2D, texture[1]);            // Select Our Second Texture
InBlock.gif
    glTranslatef(0.0f,0.0f,-5.0f);                        // Move Into The Screen 5 Units
InBlock.gif
    glRotatef(45.0f,0.0f,0.0f,1.0f);                    // Rotate On The Z Axis 45 Degrees (Clockwise)
InBlock.gif
    glRotatef(cnt1*30.0f,1.0f,1.0f,0.0f);                // Rotate On The X & Y Axis By cnt1 (Left To Right)
InBlock.gif
    glDisable(GL_BLEND);                                // Disable Blending Before We Draw In 3D
InBlock.gif
    glColor3f(1.0f,1.0f,1.0f);                            // Bright White
InBlock.gif
    glBegin(GL_QUADS);                                    // Draw Our First Texture Mapped Quad
InBlock.gif
        glTexCoord2d(0.0f,0.0f);                        // First Texture Coord
InBlock.gif
        glVertex2f(-1.0f1.0f);                        // First Vertex
InBlock.gif
        glTexCoord2d(1.0f,0.0f);                        // Second Texture Coord
InBlock.gif
        glVertex2f( 1.0f1.0f);                        // Second Vertex
InBlock.gif
        glTexCoord2d(1.0f,1.0f);                        // Third Texture Coord
InBlock.gif
        glVertex2f( 1.0f,-1.0f);                        // Third Vertex
InBlock.gif
        glTexCoord2d(0.0f,1.0f);                        // Fourth Texture Coord
InBlock.gif
        glVertex2f(-1.0f,-1.0f);                        // Fourth Vertex
InBlock.gif
    glEnd();                                            // Done Drawing The First Quad
InBlock.gif
    glRotatef(90.0f,1.0f,1.0f,0.0f);                    // Rotate On The X & Y Axis By 90 Degrees (Left To Right)
InBlock.gif
    glBegin(GL_QUADS);                                    // Draw Our Second Texture Mapped Quad
InBlock.gif
        glTexCoord2d(0.0f,0.0f);                        // First Texture Coord
InBlock.gif
        glVertex2f(-1.0f1.0f);                        // First Vertex
InBlock.gif
        glTexCoord2d(1.0f,0.0f);                        // Second Texture Coord
InBlock.gif
        glVertex2f( 1.0f1.0f);                        // Second Vertex
InBlock.gif
        glTexCoord2d(1.0f,1.0f);                        // Third Texture Coord
InBlock.gif
        glVertex2f( 1.0f,-1.0f);                        // Third Vertex
InBlock.gif
        glTexCoord2d(0.0f,1.0f);                        // Fourth Texture Coord
InBlock.gif
        glVertex2f(-1.0f,-1.0f);                        // Fourth Vertex
InBlock.gif
    glEnd();                                            // Done Drawing Our Second Quad
InBlock.gif
    glEnable(GL_BLEND);                                    // Enable Blending
InBlock.gif

InBlock.gif    glLoadIdentity();                                    
// Reset The View
InBlock.gif    
// Pulsing Colors Based On Text Position
InBlock.gif
    glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
InBlock.gif    glPrint(
int((280+250*cos(cnt1))),int(235+200*sin(cnt2)),"China",0);        // Print GL Text To The Screen
InBlock.gif

InBlock.gif    glColor3f(
1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)),1.0f*float(cos(cnt1)));
InBlock.gif    glPrint(
int((280+230*cos(cnt2))),int(235+200*sin(cnt1)),"OpenGL",1);    // Print GL Text To The Screen
InBlock.gif

InBlock.gif    glColor3f(
0.0f,0.0f,1.0f);                            // Set Color To Blue
InBlock.gif
    glPrint(int(240+200*cos((cnt2+cnt1)/5)),2,"phinecos",0);
InBlock.gif
InBlock.gif    glColor3f(
1.0f,1.0f,1.0f);                            // Set Color To White
InBlock.gif
    glPrint(int(242+200*cos((cnt2+cnt1)/5)),2,"phinecos",0);
InBlock.gif
InBlock.gif    
return TRUE;                                        // Everything Went OK}
ExpandedBlockEnd.gif
}

None.gif
None.gifBOOL COpenGLDemoView::InitGL(GLvoid)                                        
// All Setup For OpenGL Goes Here
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
if (!LoadGLTextures())                                // Jump To Texture Loading Routine ( NEW )
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        
return FALSE;                                    // If Texture Didn't Load Return FALSE
ExpandedSubBlockEnd.gif
    }

InBlock.gif
InBlock.gif    BuildFont();                                        
// Build The Font
InBlock.gif
    glClearColor(0.0f0.0f0.0f0.0f);                // Clear The Background Color To Black
InBlock.gif
    glClearDepth(1.0);                                    // Enables Clearing Of The Depth Buffer
InBlock.gif
    glDepthFunc(GL_LEQUAL);                                // The Type Of Depth Test To Do
InBlock.gif
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);                    // Select The Type Of Blending
InBlock.gif
    glShadeModel(GL_SMOOTH);                            // Enables Smooth Color Shading
InBlock.gif
    glEnable(GL_TEXTURE_2D);                            // Enable 2D Texture Mapping
InBlock.gif

InBlock.gif    
return TRUE;                                        // Initialization Went OK
ExpandedBlockEnd.gif
}

None.gif
None.gif

200782705.jpg