⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skybox.cpp

📁 此程序需要Brew sdk2.1版本以上,是关于OpenGL的手机编程.
💻 CPP
字号:
/*=================================================================================
FILE:			skybox.cpp
  
DESCRIPTION:	This file is provide as a standard sample Brew source file. 
				Please refer to this OpenGL(R)ES brew sample application as a 
				reference on how to use the standard OpenGL-ES and EGL APIs.
                          
AUTHOR:			QUALCOMM 
                        
				Copyright (c) 2004 QUALCOMM Incorporated.
					   All Rights Reserved.
					QUALCOMM Proprietary/GTDR
=================================================================================*/

/*-------------------------------------------------------------------------------*
 *                      I N C L U D E   F I L E S                                *
 *-------------------------------------------------------------------------------*/
#include "skybox.h"

/*-------------------------------------------------------------------------------*
 *                          B E G I N   P R O G R A M                            *
 *-------------------------------------------------------------------------------*/

/*===========================================================================
FUNCTION: skybox::skybox
  
DESCRIPTION:
	Constructor of the skybox class 
   
PROTOTYPE:
	skybox::skybox()
      
PARAMETERS:
	none
            
DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
skybox::skybox()
{
}


/*===========================================================================
FUNCTION: skybox::skybox
  
DESCRIPTION:
	Destructor of the skybox class 
   
PROTOTYPE:
	skybox::~skybox()
      
PARAMETERS:
	none
            
DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
skybox::~skybox()
{
}


/*===========================================================================
FUNCTION: skybox::Render
  
DESCRIPTION:
	The rendering the sky box routine 
   
PROTOTYPE:
	void skybox::Render()
      
PARAMETERS:
    none
            
DEPENDENCIES
	none
              
RETURN VALUE
	none
                
===========================================================================*/
void skybox::Render()
{
	glPushMatrix();


    GLint vertices[72] = {

        	// top
			-SKY_SIZE, SKY_SIZE, SKY_SIZE,		
            SKY_SIZE,  SKY_SIZE, SKY_SIZE,		
            SKY_SIZE,  SKY_SIZE, -SKY_SIZE,		
            -SKY_SIZE, SKY_SIZE, -SKY_SIZE,

			// bottom
			-SKY_SIZE, -SKY_SIZE, SKY_SIZE,		
            -SKY_SIZE, -SKY_SIZE, -SKY_SIZE,		
            SKY_SIZE,  -SKY_SIZE, -SKY_SIZE,		
            SKY_SIZE,  -SKY_SIZE, SKY_SIZE,

            // front
			-SKY_SIZE, -SKY_SIZE, SKY_SIZE,		
            SKY_SIZE,  -SKY_SIZE, SKY_SIZE,		
            SKY_SIZE,  SKY_SIZE, SKY_SIZE,		
            -SKY_SIZE, SKY_SIZE, SKY_SIZE,

			// back
			SKY_SIZE,  -SKY_SIZE, -SKY_SIZE,		
            -SKY_SIZE, -SKY_SIZE, -SKY_SIZE,		
            -SKY_SIZE, SKY_SIZE, -SKY_SIZE,		
            SKY_SIZE,  SKY_SIZE, -SKY_SIZE, 

            //right
			SKY_SIZE, -SKY_SIZE, SKY_SIZE,		
            SKY_SIZE, -SKY_SIZE, -SKY_SIZE,		
            SKY_SIZE, SKY_SIZE, -SKY_SIZE,		
            SKY_SIZE, SKY_SIZE, SKY_SIZE,

			// left
			-SKY_SIZE, -SKY_SIZE, -SKY_SIZE,		
            -SKY_SIZE, -SKY_SIZE, SKY_SIZE,		
            -SKY_SIZE, SKY_SIZE, SKY_SIZE,		
            -SKY_SIZE, SKY_SIZE, -SKY_SIZE };


		GLshort texCoords [48] = {
            0, 1, 0, 0, 1, 0, 1, 1,  
			1, 0, 1, 1, 0, 1, 0, 0, 
			1, 1, 0, 1, 0, 0, 1, 0,
			1, 1, 0, 1, 0, 0, 1, 0,
			1, 1, 0, 1, 0, 0, 1, 0,
			1, 1, 0, 1, 0, 0, 1, 0
			};


	GLubyte top[]		= {0, 1, 2, 3};
	GLubyte bottom[]	= {4, 5, 6, 7};
	GLubyte front[]	= {8, 9, 10, 11};
	GLubyte back[]	= {12, 13, 14, 15};
	GLubyte right[]	= {16, 17, 18, 19};
	GLubyte left[]	= {20, 21, 22, 23};



    //int v=0;
	long ViewMatrixFx[16];

	glDisable( GL_DEPTH_TEST );

	//m_frame_time =1 ;
	glShadeModel( GL_FLAT );

	glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

    // Constrain how far we allow zooming like movement
	if(m_skyboxMove>4)			m_skyboxMove=4;
	else if (m_skyboxMove <-4)	m_skyboxMove=-4;

    // Constrain how far up and down we allow the skybox to rotate
	if(m_skyboxRotX>11)			m_skyboxRotX=11;
	else if (m_skyboxRotX <-11)	m_skyboxRotX=-11;

    // Create a view matrix of where to look at
	xxgluLookAtMatrixFx(ViewMatrixFx, 
                        0,0,INT_TO_Q16(m_skyboxMove-8),    // position of viewer

                        0, (m_skyboxRotX << 14), 0,         // Where to look
                                                            // Note: the shift left by 14
                                                            //       is so that the rotation
                                                            //       goes 1/4 the speed 
                                                            //       of using INT_TO_Q16

                        0, INT_TO_Q16(1), 0 );              // Up axis

    // Apply the view matrix
	glMultMatrixx((GLfixed*)ViewMatrixFx);


    glRotatex((m_skyboxRotY<<15), INT_TO_Q16(0), INT_TO_Q16(1), INT_TO_Q16(0));

	glDisable(GL_FOG);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	glEnable(GL_TEXTURE_2D);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer(3, GL_FIXED, 0, vertices);
	glTexCoordPointer(2, GL_SHORT, 0, texCoords);

	glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	// Top
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_TOP]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, top);

	// Bottom
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BOTTOM]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, bottom);

	// Front
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_FRONT]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, front);

	// Back
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BACK]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, back);

	// Right
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_RIGHT]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, right);

	// Left
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_LEFT]);
	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, left);

	glPopMatrix();
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -