Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

# ExManagerVertexProgram.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020
    00021  *
    00022  */
    00023
    00024 #include "ExManagerVertexProgram.h"
    00025
    00026 bool ExManagerVertexProgram::m_flag = false;
    00027 ExManagerVertexProgram* ExManagerVertexProgram::m_instance = NULL;
    00028
    00029 ExManagerVertexProgram* ExManagerVertexProgram::CreateSingleton(void){
    00030 Guard(ExManagerVertexProgram* ExManagerVertexProgram::CreateSingleton(void))
    00031         if(!m_flag)
    00032         {
    00033                 m_flag = true; // We are creating the error log now, so set flag to true
    00034                 m_instance = new ExManagerVertexProgram; // Create the error log
    00035         }else
    00036         {
    00037                 std::cout<<"Error singleton already created"<<std::endl;
    00038         }
    00039         return m_instance;
    00040 UnGuard
    00041 }
    00042
    00043 ExManagerVertexProgram::ExManagerVertexProgram (void)
    00044 {
    00045
    00046 }
    00047
    00048 ExManagerVertexProgram::~ExManagerVertexProgram (void)
    00049 {
    00050
    00051 }
    00052
    00053 void ExManagerVertexProgram::Init (void)
    00054 {
    00055 Guard (void ExManagerVertexProgram::init (void))
    00056         /*char *ext = (char*)glGetString( GL_EXTENSIONS );
    00057
    00058         if( strstr( ext, "GL_NV_vertex_program" ) == NULL )
    00059         {
    00060                 std::cout<<"GL_NV_vertex_program extension was not found"<<std::endl;
    00061                 return;
    00062         }
    00063         else
    00064         {
    00065                 glGenProgramsNV        = (PFNGLGENPROGRAMSNVPROC)wglGetProcAddress("glGenProgramsNV");
    00066                 glDeleteProgramsNV     = (PFNGLDELETEPROGRAMSNVPROC)wglGetProcAddress("glDeleteProgramsNV");
    00067                 glBindProgramNV        = (PFNGLBINDPROGRAMNVPROC)wglGetProcAddress("glBindProgramNV");
    00068                 glLoadProgramNV        = (PFNGLLOADPROGRAMNVPROC)wglGetProcAddress("glLoadProgramNV");
    00069                 glProgramParameter4fNV = (PFNGLPROGRAMPARAMETER4FNVPROC)wglGetProcAddress("glProgramParameter4fNV");
    00070                 glTrackMatrixNV        = (PFNGLTRACKMATRIXNVPROC)wglGetProcAddress("glTrackMatrixNV");
    00071
    00072                 if( !glGenProgramsNV || !glDeleteProgramsNV || !glBindProgramNV ||
    00073                 !glLoadProgramNV || !glProgramParameter4fNV || !glTrackMatrixNV )
    00074                 {
    00075                         std::cout<<"One or more GL_NV_vertex_program functions were not found"<<std::endl;
    00076                         return;
    00077                 }
    00078         }
    00079         // Create the vertex program
    00080     glGenProgramsNV( 1, &g_vertexProgramID );
    00081
    00082     unsigned char *shader_assembly = readShaderFile( "../Data/VertexProgram/fog.nvv" );
    00083
    00084     glLoadProgramNV( GL_VERTEX_PROGRAM_NV, g_vertexProgramID,
    00085                      strlen((char*) shader_assembly), shader_assembly );
    00086
    00087     delete shader_assembly;*/
    00088 UnGuard
    00089 }
    00090
    00091 void ExManagerVertexProgram::Reset (void)
    00092 {
    00093 Guard (void ExManagerVertexProgram::Reset (void))
    00094         ExManagerObject<ExCVertexProgram>::Reset();
    00095 UnGuard
    00096 }
    00097
    00098 unsigned char *ExManagerVertexProgram::readShaderFile( const char *fileName )
    00099 {
    00100 Guard(unsigned char *ExManagerVertexProgram::readShaderFile( const char *fileName ))
    00101     FILE *file = fopen( fileName, "r" );
    00102
    00103     if( file == NULL )
    00104     {
    00105                 std::cout<<"Cannot open shader file!"<<std::endl;
    00106                 return 0;
    00107     }
    00108
    00109     struct _stat fileStats;
    00110
    00111     if( _stat( fileName, &fileStats ) != 0 )
    00112     {
    00113         std::cout<<"Cannot get file stats for shader file!"<<std::endl;
    00114         return 0;
    00115     }
    00116
    00117     unsigned char *buffer = new unsigned char[fileStats.st_size];
    00118
    00119         int bytes = fread( buffer, 1, fileStats.st_size, file );
    00120
    00121     buffer[bytes] = 0;
    00122
    00123         fclose( file );
    00124
    00125         return buffer;
    00126 UnGuard
    00127 }
    00128
    00129 struct Vertex
    00130 {
    00131     unsigned char r, g, b, a;
    00132     float x, y, z;
    00133 };
    00134
    00135 Vertex g_quadVertices[] =
    00136 {
    00137 //     r    g    b    a      x     y     z
    00138     { 255, 255,   0, 255, -1.0f,-1.0f, 0.0f, }, // Bottom-Left,  color = yellow
    00139     { 255,   0,   0, 255,  1.0f,-1.0f, 0.0f, }, // Bottom-Right, color = red
    00140     {   0, 255,   0, 255,  1.0f, 1.0f, 0.0f, }, // Top-Right,    color = green
    00141     {   0,   0, 255, 255, -1.0f, 1.0f, 0.0f  }, // Top-Left,     color = blue
    00142 };
    00143
    00144 void ExManagerVertexProgram::Draw (void)
    00145 {
    00146 Guard (void ExManagerVertexProgram::Draw (void))
    00147         std::cout<<"Draw"<<std::endl;
    00148         //glMatrixMode( GL_MODELVIEW );
    00149     //glLoadIdentity();
    00150         glTranslatef( 0.0f, 0.0f, -5.0f );
    00151   //  glRotatef( -45, 1.0f, 0.0f, 0.0f );
    00152    // glRotatef( -g_fSpinX, 0.0f, 1.0f, 0.0f );
    00153
    00154     // Track the combined model-view-projection matrix in registers c[0]-c[3]
    00155     glTrackMatrixNV( GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV );
    00156         std::cout<<"glTrackMatrixNV"<<std::endl;ExNihilo::ShowGlError();
    00157     // Load a constant color into register c[4]
    00158
    00159     glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 4, 0.0f, 1.0f, 0.0f, 0.0f );
    00160         std::cout<<"glProgramParameter4fNV"<<std::endl;ExNihilo::ShowGlError();
    00161         glBindProgramNV( GL_VERTEX_PROGRAM_NV, g_vertexProgramID );
    00162         std::cout<<"glBindProgramNV"<<std::endl;ExNihilo::ShowGlError();
    00163         glEnable( GL_VERTEX_PROGRAM_NV );
    00164         std::cout<<"glEnable"<<std::endl;ExNihilo::ShowGlError();
    00165         glInterleavedArrays( GL_C4UB_V3F, 0, g_quadVertices );
    00166         glDrawArrays( GL_QUADS, 0, 4 );
    00167
    00168         glDisable( GL_VERTEX_PROGRAM_NV );
    00169         std::cout<<"glDisable"<<std::endl;ExNihilo::ShowGlError();
    00170
    00171 UnGuard
    00172 }
    00173
    00174