void SetupRC() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); shader = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR); MVPMatrixLocation = glGetUniformLocation(shader,"MVPMatrix"); normalMatrixLocation = glGetUniformLocation(shader,"normalMatrix"); MVMatrixLocation = glGetUniformLocation(shader,"MVMatrix"); shaderPositionLocation = glGetUniformLocation(shader, "light1.position"); shaderColorLocation = glGetUniformLocation(shader, "light1.color"); shaderAngleLocation = glGetUniformLocation(shader, "light1.angle"); shaderAttenuation0Location = glGetUniformLocation(shader, "light1.attenuation0"); shaderAttenuation1Location = glGetUniformLocation(shader, "light1.attenuation1"); shaderAttenuation2Location = glGetUniformLocation(shader, "light1.attenuation2"); shaderAmbientColorLocation = glGetUniformLocation(shader, "material.ambientColor"); shaderDiffuseColorLocation = glGetUniformLocation(shader, "material.diffuseColor"); shaderSpecularColorLocation = glGetUniformLocation(shader, "material.specularColor"); shaderSpecularExponentLocation = glGetUniformLocation(shader, "material.specularExponent"); glEnable(GL_DEPTH_TEST); LoadVertices(); LoadFaces(); }
CBspMapMeshProvider::CBspMapMeshProvider(CBspFile* bspFile, CBspMapResourceProvider* bspMapResourceProvider) : m_bspFile(bspFile) , m_bspMapResourceProvider(bspMapResourceProvider) , m_faceVisibleSet(NULL) , m_faceVisibleSetSize(0) { LoadFaces(); const unsigned int batchCount = 256; m_batches.resize(batchCount); for(unsigned int i = 0; i < batchCount; i++) { m_batches[i] = BatchMeshPtr(new CBatchMesh(1024, 4096, Palleon::VERTEX_BUFFER_HAS_POS | Palleon::VERTEX_BUFFER_HAS_UV0 | Palleon::VERTEX_BUFFER_HAS_UV1 | Palleon::VERTEX_BUFFER_HAS_COLOR)); } }
void LoadBetweenFight(Window *ParentWindow, bool bFirstInit) { if(bFirstInit == false && bInitialisedBetweenFight) return; bInitialisedBetweenFight = true; LoadBackground(ParentWindow); LoadFaces(ParentWindow); LoadStatsText(ParentWindow); StepBarsLayer = layer_create(GRect(TEXTSTARTX, 128, 91, 24)); Layer *AnimLayer = GetAnimLayer(); layer_add_child(AnimLayer/*window_get_root_layer(ParentWindow)*/, StepBarsLayer); layer_set_update_proc(StepBarsLayer, DrawStepsBars); //testing app_timer_register(1000, UpdateStats, NULL); //1fps }
void HDRTextureCube::Load(const string fileName) { string path = string(HDR_RELATIVE_PATH) + fileName + string(HDR_EXT); cout << "Loading hdr texture " << path << ".." << endl; FILE* file = fopen(path.c_str(), "rb"); RGBE_ReadHeader(file, &width, &height, NULL); data = new float[3 * width * height]; RGBE_ReadPixels_RLE(file, data, width, height); fclose(file); LoadFaces(); cout << " - width : " << width << "px" << endl; cout << " - height : " << height << "px" << endl; cout << " - memory size : " << (3 * width * height * sizeof(float)) / 8 << " bytes" << endl; cout << "Generating texture cube.." << endl; }
Obj* obj_load(char *filename) { // open and read obj file int i; Obj *newobject; if((stream = fopen( filename, "r+t" )) != NULL ) { // load objects, faces, and vertices How many objects in this file ? obj_CountObjects(); for (i=numobjects - objectsInFile;i<numobjects;i++) { // need error check here and other mallocs newobject = (Obj *)malloc(sizeof(Obj)); gameobject[i] = newobject; // Load in the faces LoadFaces(i - (numobjects - objectsInFile)); // Load the vertices LoadVertices(i - (numobjects - objectsInFile)); } fclose( stream ); } return newobject; }
////////////////////BSP::Load/////////////// //////////////////////////////////////////// bool BSP::Load(char * filename, int curveTesselation) { FILE * file; file=fopen(filename, "rb"); if(!file) { errorLog.OutputError("Unable to open %s", filename); return false; } //read in header fread(&header, sizeof(BSP_HEADER), 1, file); //check header data is correct if( header.string[0]!='I' || header.string[1]!='B' || header.string[2]!='S' || header.string[3]!='P' || header.version !=0x2E ) { errorLog.OutputError("%s is not a version 0x2E .bsp map file", filename); return false; } //Load in vertices if(!LoadVertices(file)) return false; //Load in mesh indices //Calculate number of indices int numMeshIndices=header.directoryEntries[bspMeshIndices].length/sizeof(int); //Create space meshIndices=new int[numMeshIndices]; if(!meshIndices) { errorLog.OutputError("Unable to allocate memory for %d mesh indices", numMeshIndices); return false; } //read in the mesh indices fseek(file, header.directoryEntries[bspMeshIndices].offset, SEEK_SET); fread(meshIndices, header.directoryEntries[bspMeshIndices].length, 1, file); //Load in faces if(!LoadFaces(file, curveTesselation)) return false; //Load textures if(!LoadTextures(file)) return false; //Load Lightmaps if(!LoadLightmaps(file)) return false; //Load BSP Data if(!LoadBSPData(file)) return false; //Load in entity string entityString=new char[header.directoryEntries[bspEntities].length]; if(!entityString) { errorLog.OutputError( "Unable to allocate memory for %d length entity string", header.directoryEntries[bspEntities].length); return false; } //Go to entity string in file fseek(file, header.directoryEntries[bspEntities].offset, SEEK_SET); fread(entityString, 1, header.directoryEntries[bspEntities].length, file); //Output the entity string //errorLog.OutputSuccess("Entity String: %s", entityString); fclose(file); errorLog.OutputSuccess("%s Loaded successfully", filename); return true; }
void dxModel::Load(const char * filename, bool fullpath) { Free(); FS_Change(FS_LOADING); loading_percent = 0; StrPool_Clear(); DX_SAFE_FREE(mod_base); //free old map char fullfilename[MAX_PATH]; if (fullpath) { static char temp[MAX_PATH]; static char dirname[MAX_PATH]; Str_ExtractDirName(filename, temp); Str_ExtractDirName(temp, dirname); Str_ExtractDirName(dirname, temp); strcat_s(temp, "\\valve"); sysvar.basedir = dirname; sysvar.basedir_valve = temp; strcpy_s(fullfilename, filename); } else { sysvar.basedir = default_basedir; sysvar.basedir = default_basedir; sprintf_s(fullfilename, MAX_PATH, "%s\\maps\\%s.bsp", sysvar.basedir, filename); } FILE * f = NULL; fopen_s(&f, fullfilename, "rb"); if (!f) { Sys_Error("could not open file %s", fullfilename); } fseek(f, 0, SEEK_END); long filesize = ftell(f); fseek(f, 0, SEEK_SET); mod_base = (char*)DX_MEM_ALLOC(filesize); if (!mod_base) { fclose(f); Sys_Error("could not alloc memory"); } fread(mod_base, 1, filesize, f); fclose(f); dheader_s * header = (dheader_s*)mod_base; int v = Swap_LittleLong(header->version); if (v != BSPVERSION) { Sys_Error("bad bsp version"); } for (int i = 0; i < HEADER_LUMPS; i++) { header->lumps[i].fileofs = Swap_LittleLong(header->lumps[i].fileofs); header->lumps[i].filelen = Swap_LittleLong(header->lumps[i].filelen); } UpdateLoadingPercent(6); //load entities first, we need wad file list LoadEntities(&header->lumps[LUMP_ENTITIES]); UpdateLoadingPercent(12); LoadVertexes(&header->lumps[LUMP_VERTEXES]); UpdateLoadingPercent(18); LoadEdges(&header->lumps[LUMP_EDGES]); UpdateLoadingPercent(24); LoadSurfedges(&header->lumps[LUMP_SURFEDGES]); UpdateLoadingPercent(30); LoadTextures(&header->lumps[LUMP_TEXTURES]); UpdateLoadingPercent(36); LoadLighting(&header->lumps[LUMP_LIGHTING]); UpdateLoadingPercent(42); LoadPlanes(&header->lumps[LUMP_PLANES]); UpdateLoadingPercent(48); LoadTexinfo(&header->lumps[LUMP_TEXINFO]); UpdateLoadingPercent(54); LoadFaces(&header->lumps[LUMP_FACES]); UpdateLoadingPercent(60); LoadMarksurfaces(&header->lumps[LUMP_MARKSURFACES]); UpdateLoadingPercent(66); LoadVisibility(&header->lumps[LUMP_VISIBILITY]); UpdateLoadingPercent(72); LoadLeafs(&header->lumps[LUMP_LEAFS]); UpdateLoadingPercent(78); LoadNodes(&header->lumps[LUMP_NODES]); UpdateLoadingPercent(84); LoadClipnodes(&header->lumps[LUMP_CLIPNODES]); UpdateLoadingPercent(90); LoadSubmodels(&header->lumps[LUMP_MODELS]); UpdateLoadingPercent(100); LoadSky(); DX_SAFE_FREE(mod_base); visleafs = numleafs; if (numsubmodels > 0) { visleafs = submodels[0].visleafs; } InitViewer(); loaded = true; FS_Change(FS_DEMO); }
//-------------------------------------------------------------------- std::vector<UnifiedParticle>* ObjectLoader::LoadParticles(const std::string& file_name, const float scale_x, const float scale_y, const float scale_z, const float spacing, UnifiedParticle& particle_template) { std::vector<UnifiedParticle>* result = new std::vector<UnifiedParticle>(); std::vector<Face*> faces; try { faces = LoadFaces(file_name); } catch(FileNotFound) { std::cout << file_name << " could not be found!" << std::endl; } catch(FileError) { std::cout << "There was an error loading " << file_name << "." << std::endl; } std::vector<Face*>::iterator end_iter = faces.end(); if(faces.begin() == end_iter) // true for empty files/after catching an error { return result; } // find the smallest and greatest values of all coordinates vmml::Vector3f min_vec, max_vec; faces[0]->GetBoundaryBox(min_vec, max_vec); for(std::vector<Face*>::iterator f = faces.begin(); f != end_iter; ++f) { Face* face = *f; vmml::Vector3f current_min, current_max; face->GetBoundaryBox(current_min, current_max); for(int i=0;i<3;++i) { min_vec[i] = std::min(min_vec[i],current_min[i]); max_vec[i] = std::max(max_vec[i],current_max[i]); } } // place the particles float x_steps = (max_vec[0]-min_vec[0])*scale_x/spacing; float y_steps = (max_vec[1]-min_vec[1])*scale_y/spacing; float z_steps = (max_vec[2]-min_vec[2])*scale_z/spacing; vmml::Vector3f outside = min_vec - spacing; vmml::Vector3f current_pos = min_vec; // position to evaluate in 3d model coords int particles_tried=0; // DEL for(int x=0; x <= x_steps; ++x) { current_pos[1] = min_vec[1]+(x%2)*spacing/(2*scale_y); for(int y=0; y <= y_steps; ++y) { current_pos[2] = min_vec[2]+(x%2)*spacing/(2*scale_z); for(int z=0; z <= z_steps; ++z) { bool should_add = false; for(std::vector<Face*>::iterator f = faces.begin(); f != end_iter; ++f) { Face* face = *f; if(face->DoesLineIntersect(outside,current_pos)) // add particle if number of intersection isn't odd { should_add = !should_add; } else if(face->DoesPointTouch(current_pos)) // add particles on boundaries { should_add = true; break; } } if(should_add) { particle_template.position.set((current_pos[0]-min_vec[0])*scale_x, (current_pos[1]-min_vec[1])*scale_y, (current_pos[2]-min_vec[2])*scale_z); result->push_back(particle_template); } ++particles_tried; // DEL current_pos[2] += spacing/scale_z; } current_pos[1] += spacing/scale_y; } current_pos[0] += spacing/scale_x; } std::cout << "faces: " << faces.size() << " particles: " << result->size() << " tried: " << particles_tried << std::endl; // DEL // get rid of the faces for(std::vector<Face*>::iterator f = faces.begin(); f != end_iter; ++f) { Face* face = *f; delete face; } return result; }