int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_ACCUM); glutInitWindowSize(XRES,YRES); glutInitWindowPosition(300,50); glutCreateWindow("Beautiful Teapot"); sprogram=set_shaders(); load_obj(sprogram, "teapot.605.obj"); load_texture( "glaz.ppm", TEXTURE1, sprogram); load_texture( "snow.ppm", TEXTURE2, sprogram); load_texture( "sky.ppm", TEXTURE3, sprogram); load_texture( "teabump.ppm", NORMAL1, sprogram); glActiveTexture(GL_TEXTURE0); build_shadowmap(); glBindBuffer(GL_ARRAY_BUFFER, mybuf); glBufferData(GL_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), NULL+0); glTexCoordPointer(2, GL_FLOAT, 2*sizeof(GLfloat), NULL+numFaces*3*4*sizeof(GLfloat)); glNormalPointer(GL_FLOAT, 3*sizeof(GLfloat), NULL+numFaces*(3*4+2*4)*sizeof(GLfloat)); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glutDisplayFunc(do_stuff); glutMainLoop(); return 0; }
int load_scene_open(t_prog *prog, char *str) { char **file; t_coord dir; if (((file = str_to_wordtab(str, "\n")) == NULL) || (load_scene_open_beg(prog, file))) return (-1); prog->cam_fov.y = prog->cam_fov.x * ((prog->win_size.x / prog->win_size.y) / 1.5); if (get_cam_pos(file, prog) == 1 || get_cam_look_at(file, prog) == 1 || load_mat(prog, file) == -1 || load_light(prog, file) == -1 || load_obj(prog, file) == -1) return (-1); if (prog->look_at.x == prog->cam_pos.x && prog->look_at.y == prog->cam_pos.y && prog->look_at.z == prog->cam_pos.z) return (my_printf(2, "Wrong camera placement\n") - 1); dir = normalize(minus_point(prog->look_at, prog->cam_pos)); prog->cam_rot.x = RTD(acos(-(dir.z / sqrt(pow(dir.x, 2) + pow(dir.z, 2))))) - 90; prog->cam_rot.y = RTD((M_PI / 2 - acos(dir.y))); prog->cam_dir = normalize(minus_point(prog->look_at, prog->cam_pos)); free_tab(file); return (0); }
int Database::load() { if (open() != 0) return -1; Json::Reader reader; if (!reader.parse(file_in, root, false)){ ERR("Json reader parse error, maybe empty file\n"); root.clear(); return -1; } try { Json::Value::Members member = root.getMemberNames(); Json::Value::Members::iterator it = member.begin(); for (; it != member.end(); it++){ if (load_obj(string_to_wstring(*it)) == NULL) ERR("Load object error\n"); } } catch (Json::LogicError & e) { cout << e.what() << endl; ERR("Json file data not correct\n"); close_json(); return -1; } return 0; }
void initTorus() { vector<vec3> vertices; vector<vec3> normals; vector< vector<int> > elements; //load_obj("ring2nonorm.obj", vertices, normals, elements); load_obj("ring2.obj", vertices, normals, elements); glNewList(torusDL, GL_COMPILE); for (int i =0; i < elements.size(); i++) { vector<int> currentFace = elements.at(i); glBegin(GL_POLYGON); for (int f=0; f< currentFace.size(); f +=2) { int n = currentFace.at(f); int n_norm = currentFace.at(f+1); vec3 currentVert = vertices.at(n-1); vec3 currentNorm = normals.at(n_norm-1); GLfloat vert[] = {currentVert.x, currentVert.y, currentVert.z}; GLfloat norm[] = {currentNorm.x, currentNorm.y, currentNorm.z}; glNormal3fv(norm); glVertex3fv(vert); } glEnd(); } glEndList(); }
ChessPiece::ChessPiece(string filename, string type): _file_and_path(filename), _object_type(type) { _object_id = ObjectIdFactory::getId(); _file_ok = false; _file_ok =load_obj(filename.c_str(), _vertices, _normals, _elements); }
void loadTerrain(void) { // // Aufgabe 1.a ... // load_obj("data/terrain.obj"); return; }
ModelObj::ModelObj(string filename) { bool ret =load_obj(filename.c_str(), _vertices, _normals, _elements); if(ret) { initVBO(); } }
Object * Database::find(const wstring & name, int & ret) { Object * obj = global->obj_mgr->find(name, ret); if (ret == CM_NOT_FOUND){ if (is_existent_in_json(name)){ obj = load_obj(name); ret = 0; } } return obj; }
GLObjectObjFl::GLObjectObjFl(string filename, float x, float y, float z): _file_and_path(filename) { center[0] = x; center[1] = y; center[2] = z; _file_ok = false; _file_ok =load_obj(filename.c_str(), _vertices, _normals, _elements); }
void load_mesh_or_pointcloud(const std::string &filename, MatrixXu &F, MatrixXf &V, MatrixXf &N, const ProgressCallback &progress) { std::string extension; if (filename.size() > 4) extension = str_tolower(filename.substr(filename.size()-4)); if (extension == ".ply") load_ply(filename, F, V, true, progress); else if (extension == ".obj") load_obj(filename, F, V, progress); else if (extension == ".aln") load_pointcloud(filename, V, N, progress); else throw std::runtime_error("load_mesh_or_pointcloud: Unknown file extension \"" + extension + "\" (.ply/.obj/.aln are supported)"); }
ObjModel *Resources::mesh(const std::string &meshFile) { std::string fullpath; if (meshMap.find(meshFile) == meshMap.end()) { DEBUG_PRINT("loading " << meshFile); if (search_path(meshFile, fullpath)) { meshMap[meshFile] = load_obj(fullpath); } else { DEBUG_ERROR("file " << meshFile << " doesnt exist or not reachable"); } } else { DEBUG_PRINT("using already loaded " << meshFile); } return meshMap[meshFile]; }
RENDERING_SERVICE_API int rs_load_simple_obj(SimpleStaticObject* obj) { if (!IsValidStaticObject(obj)) { return -1; } static std::unordered_map<std::string, GLuint> OnMemoryTextureResources; static std::unordered_map<std::string, VertexBuffer> OnMemoryStaticMeshResources; char resPath[1024]; if (obj->objFileName) { auto vb = OnMemoryStaticMeshResources.find(obj->objFileName); if (vb == OnMemoryStaticMeshResources.end()) { GetMmoResourcePath(resPath, _countof(resPath), obj->objFileName); load_obj(&obj->vb, resPath); OnMemoryStaticMeshResources[obj->objFileName] = obj->vb; } else { obj->vb = vb->second; } } if (obj->ddsFileName) { auto texId = OnMemoryTextureResources.find(obj->ddsFileName); if (texId == OnMemoryTextureResources.end()) { GetMmoResourcePath(resPath, _countof(resPath), obj->ddsFileName); obj->texId = load_dds(resPath); OnMemoryTextureResources[obj->ddsFileName] = obj->texId; } else { obj->texId = texId->second; } } return 0; }
void initRendering(char** argv) { glClearColor(0.678431, 0.847059, 0.901961, 1.0); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); ReadMap("hole.01.db"); ImportObj temp; ImportObj Tee = getTeeBuffer(); load_obj("BallSmall.obj", temp.Vertices, temp.Indices, glm::vec3(0, 0.08, 0)); temp.CalculateNormals(); GolfBall = Ball(temp, Tee.Coordinate, getTiles()[getTeeBuffer().TileID - 1]); //The starting tile is the tile of the Tee setShaders(); }
int main(int argc, char * argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("Load Wavefront Obj"); glutIdleFunc(&render); glutKeyboardFunc(&key_down); glutKeyboardUpFunc(&key_up); glMatrixMode(GL_PROJECTION); gluPerspective(45, 640.0 / 480.0, 1, 100); glMatrixMode(GL_MODELVIEW); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_CULL_FACE); /* lighting */ { float light_pos[] = { 0, 0, 0, 1 }; float white_light[] = { 1.1, 1.1, 1.1, 1 }; float ambient[] = { 0.4, 0.4, 0.4, 1 }; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } glClearColor(0, 0, 0, 0); glEnable(GL_DEPTH_TEST); glClearDepth(1.0); camInit(); FILE * fp = fopen("xxx.obj", "r"); go = load_obj(fp); fclose(fp); glutMainLoop(); return 0; }
void caInit(int width, int height) { program = caCreateProgram(vsrc, "position", fsrc, "gl_FragColor"); load_obj(vbo, &m, "teapot.obj"); // load_obj(vbo, &m, "elephal.obj"); aspect = (float)width / (float)height; glViewport(0, 0, width, height); glClearColor(0.6, 0.8, 0.8, 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); // カリングの有効化 // glFrontFace(GL_CCW); // 裏面を描画しない // glCullFace(GL_BACK); caKeyEvent = keyEvent; caMouseEvent = mouseEvent; }
// Constructeur : Charge l'obj et génère les Polyhedron_3 associés DegradeAnObject::DegradeAnObject(char const *input, char const *output) { this->output = output; // load the input file load_obj(input); if( coords.size() == 0 ) { std::cout << "Aucun objet n'a été chargé" << std::endl; } else { std::cout << "objet chargé" << std::endl; // build polyhedrons from the loaded arrays for(int i = 0 ; i < names.size() ; i++) { Polyhedron P; polyhedron_builder<HalfedgeDS> builder( coords[i], faces[i], minFacets[i] ); P.delegate( builder ); polys.push_back(P); } } }
bool ModelIO::load(const string& path, TriangleMesh * p_triangle_mesh) { std::ifstream in(path.c_str()); if (!in.good()) { error("file not exists: %s", path.c_str()); return false; } Assert(p_triangle_mesh != nullptr); string ext = get_file_type(path); if (ext == "obj") return load_obj(path, in, p_triangle_mesh); else error("Unsupported model file type: %s\n", ext.c_str()); return false; }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Exactly one parameter expected\n"); return 1; } model = load_obj(argv[1]); if (!model) { fprintf(stderr, "Can't load model %s\n", argv[1]); return 2; } glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(spinDisplay); glutMainLoop(); }
void emu_load(struct em8051 *aCPU) { WINDOW * exc; int pos = 0; int ch = 0; int result; pos = (int)strlen(filename); runmode = 0; setSpeed(speed, runmode); exc = subwin(stdscr, 5, 50, (LINES-6)/2, (COLS-50)/2); wattron(exc, A_REVERSE); werase(exc); box(exc,ACS_VLINE,ACS_HLINE); mvwaddstr(exc, 0, 2, "Load Intel HEX File"); wattroff(exc, A_REVERSE); wmove(exc, 2, 2); // 12345678901234567890123456780123456789012345 waddstr(exc,"[____________________________________________]"); wmove(exc,2,3); waddstr(exc, filename); wrefresh(exc); while (ch != '\n') { ch = getch(); if (ch > 31 && ch < 127 || ch > 127 && ch < 255) { if (pos < 44) { filename[pos] = ch; pos++; filename[pos] = 0; waddch(exc,ch); wrefresh(exc); } } if (ch == KEY_DC || ch == 8 || ch == KEY_BACKSPACE) { if (pos > 0) { pos--; filename[pos] = 0; wmove(exc,2,3+pos); waddch(exc,'_'); wmove(exc,2,3+pos); wrefresh(exc); } } } result = load_obj(aCPU, filename); delwin(exc); refreshview(aCPU); switch (result) { case -1: emu_popup(aCPU, "Load error", "File not found."); break; case -2: emu_popup(aCPU, "Load error", "Bad file format."); break; case -3: emu_popup(aCPU, "Load error", "Unsupported HEX file version."); break; case -4: emu_popup(aCPU, "Load error", "Checksum failure."); break; case -5: emu_popup(aCPU, "Load error", "No end of data marker found."); break; } }
bool game::OnInit() { if ( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { return false; } // TODO necessary?!? atexit( SDL_Quit ); if ( ( surface = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL ) ) = NULL ) { return false; } glClearColor( 0, 0, 0, 0 ); glClearDepth( 1.0f ); glViewport( 0, 0, width, height ); // initialize glew GLenum err = glewInit(); if ( err != GLEW_OK ) { fprintf( stderr, "Error initializing GLEW: %s\n", glewGetErrorString(err) ); } // load vertex shader GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER ); const GLchar *vertexSource = read_file( "src/shader/basic.vert" ); if ( vertexSource == NULL ) { fprintf( stderr, "Error reading vertex shader\n" ); return false; } const GLchar *vertexCodeArray[] = { vertexSource }; glShaderSource( vertexShader, 1, vertexCodeArray, NULL ); // free( (void *) vertexSource ); // compile vertex shader glCompileShader( vertexShader ); // load fragment shader GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); const GLchar *fragmentSource = read_file( "src/shader/basic.frag" ); if ( fragmentSource == NULL ) { fprintf( stderr, "Error reading fragment shader\n" ); return false; } const GLchar *fragmentCodeArray[] = { fragmentSource }; glShaderSource( fragmentShader, 1, fragmentCodeArray, NULL ); // free( (void *) fragmentSource ); // compile fragment shader glCompileShader( fragmentShader ); // create shader program GLuint programHandle = glCreateProgram(); glAttachShader( programHandle, vertexShader ); glAttachShader( programHandle, fragmentShader ); // bind attributes glBindAttribLocation( programHandle, 0, "VertexPosition" ); glBindAttribLocation( programHandle, 1, "VertexNormal" ); // generate vertex array object GLuint vaoHandle; glGenVertexArrays( 1, &vaoHandle ); glBindVertexArray( vaoHandle ); // generate vertex buffer objects GLuint vboHandles[3]; glGenBuffers( 3, vboHandles ); GLuint positionBufferHandle = vboHandles[0]; GLuint normalBufferHandle = vboHandles[1]; GLuint indexBufferHandle = vboHandles[2]; glBindBuffer( GL_ARRAY_BUFFER, positionBufferHandle ); glBufferData( GL_ARRAY_BUFFER, vertices.size() * sizeof( float ), &vertices[0], GL_STATIC_DRAW ); glBindBuffer( GL_ARRAY_BUFFER, normalBufferHandle ); glBufferData( GL_ARRAY_BUFFER, normals.size() * sizeof( float ), &normals[0], GL_STATIC_DRAW ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, vertices.size() * sizeof( int ), &elements[0], GL_STATIC_DRAW ); glEnableVertexAttribArray( 0 ); glEnableVertexAttribArray( 1 ); glEnableVertexAttribArray( 2 ); glBindBuffer( GL_ARRAY_BUFFER, positionBufferHandle ); glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *) NULL ); glBindBuffer( GL_ARRAY_BUFFER, normalBufferHandle ); glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *) NULL ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle ); glVertexAttribPointer( 2, 3, GL_UNSIGNED_INT, GL_FALSE, 0, (GLubyte *) NULL ); // link shader program glLinkProgram( programHandle ); glUseProgram( programHandle ); /* // old stuff glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, width, height, 0, 1, -1 ); glMatrixMode( GL_MODELVIEW ); glEnable( GL_TEXTURE_2D ); glLoadIdentity(); */ load_obj( "data/objects/suzanne.obj", vertices, normals, elements ); return true; }
void Cube::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext) { HRESULT hr; load_obj("../../media/objects/cube.obj"); ///////////////////////////Index Buffer //////////////////////////////// // Set up the description of the static vertex buffer. D3D11_BUFFER_DESC VertexBufferDesc; VertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; VertexBufferDesc.ByteWidth = sizeof(Vertex)* m_VertexData.size(); VertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; VertexBufferDesc.CPUAccessFlags = 0; VertexBufferDesc.MiscFlags = 0; VertexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the vertex data. D3D11_SUBRESOURCE_DATA VBO; VBO.pSysMem = &m_VertexData[0]; VBO.SysMemPitch = 0; VBO.SysMemSlicePitch = 0; // Now create the vertex buffer. hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer); //DebugHR(hr); /////////////////////////////////Index Buffer /////////////////////////////////////// // Set up the description of the static index buffer. D3D11_BUFFER_DESC IndexBufferDesc; IndexBufferDesc.Usage = D3D11_USAGE_DEFAULT; IndexBufferDesc.ByteWidth = sizeof(DWORD)* m_IndexData.size(); IndexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; IndexBufferDesc.CPUAccessFlags = 0; IndexBufferDesc.MiscFlags = 0; IndexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the index data. D3D11_SUBRESOURCE_DATA IBO; IBO.pSysMem = &m_IndexData[0]; IBO.SysMemPitch = 0; IBO.SysMemSlicePitch = 0; hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer); //DebugHR(hr); //////////////////////////////////////////////////////////////////////////////////////// // Set vertex buffer stride and offset.= unsigned int stride; unsigned int offset; stride = sizeof(Vertex); offset = 0; pD3D11DeviceContext->IASetVertexBuffers(0, 1, m_pVertexBuffer.GetAddressOf(), &stride, &offset); pD3D11DeviceContext->IASetIndexBuffer(m_pIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0); pD3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ////////////////////////////////Const Buffer////////////////////////////////////// D3D11_BUFFER_DESC mvpDesc; ZeroMemory(&mvpDesc, sizeof(D3D11_BUFFER_DESC)); mvpDesc.Usage = D3D11_USAGE_DEFAULT; mvpDesc.ByteWidth = sizeof(d3d::MatrixBuffer); mvpDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mvpDesc.CPUAccessFlags = 0; mvpDesc.MiscFlags = 0; hr = pD3D11Device->CreateBuffer(&mvpDesc, NULL, &m_pMVPBuffer); //DebugHR(hr); ///////////////////////////////////////////////////////////////////////////////// D3D11_BUFFER_DESC lightBufferDesc; ZeroMemory(&lightBufferDesc, sizeof(D3D11_BUFFER_DESC)); lightBufferDesc.Usage = D3D11_USAGE_DYNAMIC; lightBufferDesc.ByteWidth = sizeof(LightBuffer); lightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; lightBufferDesc.MiscFlags = 0; hr = pD3D11Device->CreateBuffer(&lightBufferDesc, NULL, m_pLightBuffer.GetAddressOf()); //DebugHR(hr); D3D11_MAPPED_SUBRESOURCE mappedResource; // Lock the light constant buffer so it can be written to. hr = pD3D11DeviceContext->Map(m_pLightBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); //DebugHR(hr); // Get a pointer to the data in the constant buffer. LightBuffer *dataPtr2 = (LightBuffer*)mappedResource.pData; dataPtr2->diffuseColor = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); dataPtr2->lightDirection = XMFLOAT3(0.0f, 0.0f, 1.0f); dataPtr2->padding = 0.0f; pD3D11DeviceContext->Unmap(m_pLightBuffer.Get(), 0); int lightSlot = 0; pD3D11DeviceContext->PSSetConstantBuffers(lightSlot, 1, m_pLightBuffer.GetAddressOf()); }
/** * Loads a model from a file. * Returns a pointer to the bone struct containing the data loaded. */ model *load_model(const char *file_name) { FILE *fp; char buffer[BUFF_LEN], *arg_list[MAX_ARGS]; int i, line = 0, arg_count; mesh *geo; bone *b_new; model *new_mdl = NULL; /* Attempt to open the requested file. Prints error message on error. */ if((fp = fopen(file_name, "r")) == NULL) { fprintf(stderr, "ERROR(load_model): Unable to open file '%s'.\n", file_name); return NULL; } while(fgets(buffer, BUFF_LEN - 1, fp) != NULL) { line++; /* No lines should be more then the max buffer size in length. If any * lines do breach this contraint, then the file is corrupt and will * not be loaded. */ if(buffer[strlen(buffer) - 1] != '\n') { fprintf(stderr, "ERROR(load_model): Buffer overflow in file '%s' line %d\n", file_name, line); return NULL; } buffer[strlen(buffer) - 1] = '\0'; arg_count = makeargs(buffer, SEPERATOR, arg_list, MAX_ARGS); if(arg_count == 0) continue; /* If there's an m as the first character (which there should be at the * head of each model file) then we prepare the model. */ if(buffer[0] == 'm') { if(arg_count != 4) continue; /* Create a new model struct. */ new_mdl = new_model(arg_list[1], atoi(arg_list[2])); if(new_mdl == NULL) return NULL; /* Initialise all the new models variables. */ new_mdl->texture = loadTexture(arg_list[3]); printf("New model '%s' created. Loading Model...\n", arg_list[1]); } /* If we have a bone, indicated by a b as the first character. Note that * bones can only be added if a model line has been read in. */ else if(buffer[0] == 'b') { if(new_mdl == NULL) { fprintf(stderr, "ERROR(load_mdl): Attempted load bone without model decl.\n"); continue; } if(arg_count < 7) continue; printf("Loading bone '%s' into model '%s'.\n", arg_list[1], new_mdl->name); new_mdl->n_bones++; /* Allocate memory for the bone object and various chores that need * to be done to the bone to keep it healthy. */ b_new = malloc(sizeof(bone)); if(b_new == NULL) { fprintf(stderr, "ERROR(load_model): Cannot allocate memory.\n"); exit(1); } b_new->child = NULL; b_new->sibling = NULL; b_new->child_count = 0; /** * Allocate memory for the bone name and copy the string accross. */ b_new->name = malloc(strlen(arg_list[1])); strcpy(b_new->name, arg_list[1]); /* Parse translations from the strings and put them into the bone's * translation struct. */ for(i = 0; i < TRANS_SIZE; i++) b_new->rot[i] = atof(arg_list[i + 2]); b_new->length = atof(arg_list[5]); /* Attempt to load a new mesh into the current bone. */ if(strlen(arg_list[7]) > 0) { geo = load_obj(arg_list[7]); if(geo == NULL) { fprintf(stderr, "Error loading obj %s\n", arg_list[7]); exit(1); } /* Create a vertex array out of the loaded obj and free the mesh * struct that was temporarily created. */ if(strlen(arg_list[8]) > 0 && arg_list[8][0] == 'F') b_new->geometry = mesh_to_array(geo, NORM_FLAT); else b_new->geometry = mesh_to_array(geo, NORM_SMOOTH); b_new->tri_count = geo->n_elements; free_mesh(geo); } else b_new->geometry = NULL; /* If the root bone has not been set then this is obviously the root * bone, or a file format error. */ if(new_mdl->root == NULL) { if(strlen(arg_list[6]) == 0) new_mdl->root = b_new; else { fprintf(stderr, "ERROR(load_model): Error, root bone must not have parent.\n"); free_model(new_mdl); return NULL; } } else { if(!skel_add_child(arg_list[6], new_mdl->root, b_new)) { printf("Cannot add child %s.\n", b_new->name); free_model(new_mdl); return NULL; } } } /* Start of an animation. */ else if(buffer[0] == 'a') { if(new_mdl == NULL) { fprintf(stderr, "ERROR(load_mdl): Attempted load animation without model decl.\n"); continue; } if(arg_count != 2) continue; load_animation(new_mdl, atoi(arg_list[1]), fp); } } if(new_mdl != NULL) new_mdl->bone_array = skel_make_array(new_mdl->root, new_mdl->n_bones); printf("New model '%s' successfully loaded.\n", new_mdl->name); printf("%d bones loaded.\n", new_mdl->n_bones); printf("%d animations loaded.\n", new_mdl->n_anims); return new_mdl; }
void IslandGame::initGraphics( ) { // Load Font ilGenImages( 1, &m_ilFontId ); ilBindImage( m_ilFontId ); if (!ilLoadImage( (ILstring)"gamedata/digistrip.png" )) { errorMessage("Loading font image failed\n"); } // Make a GL texture for it m_glFontTexId = ilutGLBindTexImage(); m_fntFontId = gfCreateFont( m_glFontTexId ); // A .finfo file contains the metrics for a font. These // are generated by the Fontpack utility. gfLoadFontMetrics( m_fntFontId, "gamedata/digistrip.finfo"); _RPT1( _CRT_WARN, "font has %d chars\n", gfGetFontMetric( m_fntFontId, GF_FONT_NUMCHARS ) ); // Load the player sprite m_playerTex = loadTexture( "gamedata/npc_player.png", 4 ); m_personMesh = load_obj( "gamedata/person.obj"); // Load critters m_critterMesh = load_obj( "gamedata/hemi_critter.obj"); // Load the tiles m_terrainTilesTexId = loadTexture( "gamedata/tiles.png", 4 ); m_waterTexId = loadTexture( "gamedata/water.png", 4 ); // Load sounds while we're at it FMOD_RESULT res; res = m_fmod->createSound( "gamedata/wall.wav", FMOD_HARDWARE, 0, &sfx_wall ); ERRCHECK( res ); res = m_fmod->createSound( "gamedata/blang.wav", FMOD_HARDWARE, 0, &sfx_blahblah ); ERRCHECK( res ); res = m_fmod->createStream( "gamedata/galapagos.mp3", FMOD_HARDWARE |FMOD_LOOP_NORMAL | FMOD_2D, 0, &m_music ); ERRCHECK( res ); FMOD::Channel *chan=0; res = m_fmod->playSound(FMOD_CHANNEL_FREE, m_music, false, &chan); ERRCHECK( res ); //sfx_blahblah = FSOUND_Sample_Load( FSOUND_UNMANAGED, "gamedata/sfxr_blang.wav", FSOUND_NORMAL, 0, 0 ); // Set up simple lighting GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat light_direction[] = { -0.5, 1.0, 0.5, 0.0 }; GLfloat light_ambient[] = { 2.0, 2.0, 2.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; vec3f lightDir( -0.5, 1.0, 0.5 ); lightDir.Normalize(); light_direction[0] = lightDir.x; light_direction[1] = lightDir.y; light_direction[2] = lightDir.z; //glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_direction); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); }
static inline void init_cube(t_pt_c *cube) { cube[0] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0xff0000, (t_v2f) {0, 0}, 1 }; cube[1] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 1}, 1 }; cube[2] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x00ffff, (t_v2f) {1, 0}, 1 }; cube[3] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0x00ff00, (t_v2f) {1, 1}, 1 }; cube[4] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0xff0000, (t_v2f) {0, 0}, 0 }; cube[5] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 1}, 0 }; cube[6] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x00ffff, (t_v2f) {1, 0}, 0 }; cube[7] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0xb895cb, (t_v2f) {1, 1}, 0 }; cube[8] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0xffab00, (t_v2f) {0, 0}, 0 }; cube[9] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x0cc0ff, (t_v2f) {0, 0}, 0 }; cube[10] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0xf0fff0, (t_v2f) {0, 0}, 0 }; cube[11] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0x053916, (t_v2f) {0, 0}, 0 }; cube[12] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0xffffff, (t_v2f) {0, 0}, 0 }; cube[13] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 0}, 0 }; cube[14] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x00ffff, (t_v2f) {0, 0}, 0 }; cube[15] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0x00ff00, (t_v2f) {0, 0}, 0 }; cube[16] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x000000 >> 1, (t_v2f) {0, 0}, 0 }; cube[17] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0x0000ff >> 1, (t_v2f) {0, 0}, 0 }; cube[18] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x00ffff >> 1, (t_v2f) {0, 0}, 0 }; cube[19] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x00ff00, (t_v2f) {0, 0}, 0 }; cube[20] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0xff0000 << 1, (t_v2f) {0, 0}, 0 }; cube[21] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0x0000ff << 1, (t_v2f) {0, 0}, 0 }; cube[22] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0x00fffa, (t_v2f) {0, 0}, 0 }; cube[23] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0x341e09, (t_v2f) {0, 0}, 0 }; } static GLuint texture_load(const char *filepath) { glEnable(GL_TEXTURE_2D); return (SOIL_load_OGL_texture( filepath, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y)); } static int main_loop(GLFWwindow *window, GLuint texture, const char *filepath) { t_pt_c pts[POINTS]; load_obj(filepath); init_cube(pts); while ((!glfwWindowShouldClose(window)) && (!keyboard(window))) { (void)texture; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); display(texture, pts); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return (0); } void error_handler(int id, const char *str) { ft_printf("[%2d] error: %s\n", id, str); }
void Inicjuj( sf::RenderWindow &app ) { font.loadFromFile( "fonts/comicbd.ttf" ); std::string str( "Ladowanie textur..." ); CStopWatch timer; pisz( app, str ); const char *chTextures[ LiczbaTextur ] = { "textures/background.tga", "textures/cross.tga", "textures/life.tga", "textures/blood.tga", "textures/enemy.tga", "textures/comet.tga", "textures/bullet.tga", "textures/award.tga" }; GLsizei width, height; GLenum format, type; GLvoid *pixels; glPixelStorei(GL_UNPACK_ALIGNMENT,1); for ( int i = 0; i < LiczbaTextur; ++i ){ if ( !load_targa( chTextures[i], width, height, format, type, pixels) ){ str = "Brak pliku "; str += chTextures[i]; pisz( app, str ); while ( timer.GetElapsedSeconds() < 1.0f ){ continue; } } glGenTextures(1,&t_textures[ i ]); glBindTexture(GL_TEXTURE_2D, t_textures[ i ]); gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,height,format,type,pixels); delete [] (unsigned char *)pixels; } str = "Ladowanie modeli..."; pisz( app, str ); load_obj( "models/award/WoodenBox02.obj", model_award ); load_obj( "models/comet/Rock.obj", model_rock ); load_obj( "models/bullet/bullet.obj", model_bullet ); load_obj( "models/SpaceShip/fighter.obj", model_space_ship ); str = "Ladowanie dzwiekow..."; pisz( app, str ); const char *chMusic[ LiczbaDzwiekow ] = { "sounds/MenuBackground#1.ogg", "sounds/MenuBackground#2.ogg", "sounds/Background.ogg", "sounds/fire.ogg", "sounds/Award.ogg", "sounds/ColShipComet.ogg", "sounds/ColShipShip.ogg", "sounds/CometExplo.ogg", "sounds/lifeLost.ogg", "sounds/ShipExplo.ogg", "sounds/hit.ogg" }; for ( int i = 0; i < LiczbaDzwiekow; ++i ){ if ( !sounds[i].openFromFile( chMusic[i] ) ){ str = "Brak pliku "; str += chMusic[i]; pisz( app, str ); while ( timer.GetElapsedSeconds() < 1.0f ){ continue; } } } sounds[0].setRelativeToListener( true ); sounds[1].setRelativeToListener( true ); sounds[2].setRelativeToListener( true ); sounds[3].setRelativeToListener( true ); sounds[4].setRelativeToListener( true ); sounds[8].setRelativeToListener( true ); sounds[10].setRelativeToListener( true ); sounds[2].setLoop( true ); sounds[2].setVolume( 20 ); sounds[9].setMinDistance( 7.0f ); sounds[9].setAttenuation( 15.0f ); sounds[7].setMinDistance( 7.0f ); sounds[7].setAttenuation( 15.0f ); sf::Listener::setGlobalVolume( 100.f ); sf::Listener::setDirection( 0.0f, 0.0f, -1.0f ); str = "Inicjowaie list wyswietlania..."; pisz( app, str ); ///Lista tla! list_SkyBox = glGenLists( 1 ); glNewList( list_SkyBox, GL_COMPILE ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[0] ); glBegin( GL_QUADS ); ///Tyl glNormal3f( 0.0f, 0.0f, 1.0f ); glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); glTexCoord2f(1, 1); glVertex3f(1, -1, 1); glTexCoord2f(1, 0); glVertex3f(1, 1, 1); glTexCoord2f(0, 0); glVertex3f(-1, 1, 1); glEnd(); glDisable( GL_TEXTURE_2D ); glEndList(); ///Lista celownika list_cross = glGenLists( 1 ); glNewList( list_cross, GL_COMPILE ); glColor3fv( White ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[1] ); glBegin( GL_QUADS ); glNormal3f( 0.0f, 0.0f, 1.0f ); glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); glTexCoord2f(1, 1); glVertex3f(1, -1, 1); glTexCoord2f(1, 0); glVertex3f(1, 1, 1); glTexCoord2f(0, 0); glVertex3f(-1, 1, 1); glEnd(); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); glEndList(); ///lista zycia list_life = glGenLists( 1 ); glNewList( list_life, GL_COMPILE ); glColor3fv( White ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[2] ); glBegin( GL_QUADS ); glNormal3f( 0.0f, 0.0f, 1.0f ); glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); glTexCoord2f(1, 1); glVertex3f(1, -1, 1); glTexCoord2f(1, 0); glVertex3f(1, 1, 1); glTexCoord2f(0, 0); glVertex3f(-1, 1, 1); glEnd(); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); glEndList(); ///lista krwi list_blood = glGenLists( 1 ); glNewList( list_blood, GL_COMPILE ); glColor3fv( White ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[3] ); glBegin( GL_QUADS ); glNormal3f( 0.0f, 0.0f, 1.0f ); glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); glTexCoord2f(1, 1); glVertex3f(1, -1, 1); glTexCoord2f(1, 0); glVertex3f(1, 1, 1); glTexCoord2f(0, 0); glVertex3f(-1, 1, 1); glEnd(); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); glEndList(); list_dron = glGenLists( 1 ); glNewList( list_dron, GL_COMPILE ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_COLOR_MATERIAL ); glColorMaterial( GL_FRONT, GL_AMBIENT ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[4] ); glRotatef( -90.0f, 1.0f, 0.0f, 0.0f ); glScalef( 0.22f, 0.22f, 0.22f ); glCallList( model_space_ship ); glDisable( GL_TEXTURE_2D ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_LIGHTING ); glEndList(); list_award = glGenLists( 1 ); glNewList( list_award, GL_COMPILE ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[7] ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_COLOR_MATERIAL ); glColorMaterial( GL_FRONT, GL_AMBIENT ); glCallList( model_award ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_LIGHTING ); glDisable( GL_TEXTURE_2D ); glEndList(); list_rock = glGenLists( 1 ); glNewList( list_rock, GL_COMPILE ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_COLOR_MATERIAL ); glColorMaterial( GL_FRONT, GL_AMBIENT ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[5] ); glCallList( model_rock ); glDisable( GL_TEXTURE_2D ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_LIGHTING ); glEndList(); list_bullet = glGenLists( 1 ); glNewList( list_bullet, GL_COMPILE ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, t_textures[6] ); glScaled(0.7,0.7,0.7); glCallList( model_bullet ); glDisable( GL_TEXTURE_2D ); glEndList(); str = "Pobieranie rankingu..."; pisz( app, str ); if ( DownloadFile() ) { str = "Pobieranie zakonczone..."; } else { str = "Nie udalo sie pobrac rankingu!"; } pisz( app, str ); while ( timer.GetElapsedSeconds() < 1.0f ){ continue; } str = "Tworzenie rankingu..."; pisz( app, str ); std::ifstream fin( "ranking.txt" ); if ( fin.good() ) { for ( int i = 0; i < 10; ++i ) { fin >> Top10[i].punkty; fin >> Top10[i].zycia; fin >> Top10[i].statki; fin >> Top10[i].nagrody_zdobyte; fin >> Top10[i].rozwalone_nagrody; fin >> Top10[i].rozbite_asteroidy; char ch; fin.get( ch ); ch = 'p'; while ( ch != '\n' && ch != '\r' ) { fin.get( ch ); Top10[i].name += ch; } } } else {
int main(int argc,char* argv[]) { // Initialize GLUT and process user parameters glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitWindowSize(800,800); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); // Create the window glutCreateWindow("Objects"); // Tell GLUT to call "idle" when there is nothing else to do glutIdleFunc(idle); // Tell GLUT to call "display" when the scene should be drawn glutDisplayFunc(display); // Tell GLUT to call "reshape" when the window is resized glutReshapeFunc(reshape); // Tell GLUT to call "special" when an arrow key is pressed glutSpecialFunc(special); // Tell GLUT to call "key" when a key is pressed glutKeyboardFunc(key); // Load Textures texture[0] = LoadTexBMP("znorl.bmp"); texture[1] = LoadTexBMP("metal.bmp"); texture[2] = LoadTexBMP("turquoise.bmp"); texture[3] = LoadTexBMP("stars.bmp"); texture[4] = LoadTexBMP("particle.bmp"); texture[5] = LoadTexBMP("zekador.bmp"); texture[6] = LoadTexBMP("ishthar.bmp"); texture[7] = LoadTexBMP("nesk.bmp"); texture[8] = LoadTexBMP("centura.bmp"); texture[9] = LoadTexBMP("tenav.bmp"); texture[10] = LoadTexBMP("tsarvia.bmp"); texture[11] = LoadTexBMP("kolatanevat.bmp"); texture[12] = LoadTexBMP("falarn.bmp"); texture[13] = LoadTexBMP("grass.bmp"); texture[14] = LoadTexBMP("wood.bmp"); texture[15] = LoadTexBMP("pine.bmp"); texture[16] = LoadTexBMP("water.bmp"); texture[17] = LoadTexBMP("blue.bmp"); texture[18] = LoadTexBMP("red.bmp"); texture[19] = LoadTexBMP("darkmetal.bmp"); // Load Maya objects //int num_vertices, int num_normals, int num_tex, int num_faces, char *filename // double *vertices, double *normals, double *texs, int *faces load_obj(num_vertices_voyager, num_normals_voyager, num_tex_voyager, num_faces_voyager, "voyagereng.obj", voyager_vertices, voyager_normals, voyager_texs, voyager_faces); load_obj(num_vertices_asteroid, num_normals_asteroid, num_tex_asteroid, num_faces_asteroid, "asteroid1.obj", asteroid_1_vertices, asteroid_1_normals, asteroid_1_texs, asteroid_1_faces); load_obj(num_vertices_asteroid, num_normals_asteroid, num_tex_asteroid, num_faces_asteroid, "asteroid2.obj", asteroid_2_vertices, asteroid_2_normals, asteroid_2_texs, asteroid_2_faces); load_obj(num_vertices_asteroid, num_normals_asteroid, num_tex_asteroid, num_faces_asteroid, "asteroid3.obj", asteroid_3_vertices, asteroid_3_normals, asteroid_3_texs, asteroid_3_faces); load_obj(num_vertices_asteroid, num_normals_asteroid, num_tex_asteroid, num_faces_asteroid, "asteroid_city.obj", asteroid_city_vertices, asteroid_city_normals, asteroid_city_texs, asteroid_city_faces); load_obj(num_vertices_city, num_normals_city, num_tex_city, num_faces_city, "city.obj", city_vertices, city_normals, city_texs, city_faces); load_obj(num_vertices_renegade, num_normals_renegade, num_tex_renegade, num_faces_renegade, "renegade.obj", renegade_vertices, renegade_normals, renegade_texs, renegade_faces); load_obj(num_vertices_phantom, num_normals_phantom, num_tex_phantom, num_faces_phantom, "phantom.obj", phantom_vertices, phantom_normals, phantom_texs, phantom_faces); init_particles(sun_particle, MAX_SUN_PARTICLES, 0.01, 10, 10, 1, 1, 0, 1.0, 0); init_particles(ship_particle, MAX_SHIP_PARTICLES, 0.01, 10, 10, 1, 1, 1, 1.0, 10); // Pass control to GLUT so it can interact with the user glutMainLoop(); return 0; }
int main(void) { // Allocating scene Scene * scene = new_scene(MAX_OBJECTS_NUMBER, MAX_LIGHT_SOURCES_NUMBER, BACKGROUND_COLOR); // Allocating new sphere Float radius = 100; Point3d center = point3d(0, 0, 0); Color sphere_color = rgb(250, 30, 30); Material sphere_material = material(1, 5, 5, 10, 0, 10); Object3d * sphere = new_sphere(center, radius, sphere_color, sphere_material); // Adding sphere to the scene add_object(scene, sphere); // Allocating new triangle Object3d * triangle = new_triangle(point3d(-700, -700, -130), // vertex 1 point3d( 700, -700, -130), // vertex 2 point3d( 0, 400, -130), // vertex 3 rgb(100, 255, 30), // color material(1, 6, 0, 2, 0, 0) // surface params ); // Adding triangle to the scene add_object(scene, triangle); // Loading 3D model of cow from *.obj file // defining transformations and parameters of 3D model // TODO: must be refactored... SceneFaceHandlerParams load_params = new_scene_face_handler_params(scene, // scale: 40, // move dx, dy, dz: -150, -100, 30, // rotate around axises x, y, z: 0, 0, 0, // color rgb(200, 200, 50), // surface params material(2, 3, 0, 0, 0, 0) ); load_obj("./demo/models/cow.obj", // default handler which adding polygons of 3D model to scene: scene_face_handler, &load_params); // This function is requried (bulding k-d tree of entire scene) prepare_scene(scene); printf("\nNumber of polygons: %i\n", scene->last_object_index + 1); // Allocating new light source Color light_source_color = rgb(255, 255, 255); Point3d light_source_location = point3d(-300, 300, 300); LightSource3d * light_source = new_light_source(light_source_location, light_source_color); // Adding light source to the scene add_light_source(scene, light_source); // Adding fog Float density = 0.002; set_exponential_fog(scene, density); // Allocating camera // TODO: It's a pity, but quaternions are not implemented yet :( Point3d camera_location = point3d(0, 500, 0); Float focus = 320; Float x_angle = -1.57; Float y_angle = 0; Float z_angle = 3.14; Camera * camera = new_camera(camera_location, x_angle, y_angle, z_angle, focus); // Rotate camera if needed // rotate_camera(camera, d_x_angle, d_y_angle, d_z_angle); // Move camera if needed // move_camera(camera, vector3df(d_x, d_y, d_z)); // Alocate new canvas, to render scene on it Canvas * canvas = new_canvas(CANVAS_W, CANVAS_H); render_scene(scene, camera, canvas, THREADS_NUM); // Saving rendered image in PNG format write_png("example.png", canvas); release_canvas(canvas); release_scene(scene); release_camera(camera); return 0; }
void keyEvent(int key, int action) { static int obj; char *s = 0; if (action == CATGL_ACTION_DOWN) { switch (key) { case CATGL_KEY_P: caMode = CATGL_MODE_POINT; break; case CATGL_KEY_W: caMode = CATGL_MODE_LINE; break; case CATGL_KEY_T: caMode = CATGL_MODE_TRIANGLES; break; case CATGL_KEY_RIGHT: obj++; s = getObjFile(obj); if (!s) { obj = 0; s = getObjFile(obj); } break; case CATGL_KEY_LEFT: obj--; if (obj<0) obj = 0; s = getObjFile(obj); break; case CATGL_KEY_C: { // Toggle front, back, and no culling int cullMode; glGetIntegerv(GL_CULL_FACE_MODE, &cullMode); if (glIsEnabled(GL_CULL_FACE)) { if (cullMode == GL_FRONT) { glCullFace(GL_BACK); LOGD("Culling: Culling back faces; drawing front faces\n"); } else { glDisable(GL_CULL_FACE); LOGD("Culling: No culling; drawing all faces.\n"); } } else { glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); LOGD("Culling: Culling front faces; drawing back faces\n"); } break; } case CATGL_KEY_PLUS: // increase size of points and width of lines { GLfloat currentPtSize; GLfloat sizeRange[2]; glGetFloatv(GL_POINT_SIZE, ¤tPtSize); glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, sizeRange); GLfloat temp = currentPtSize+1; if (temp > sizeRange[1]) temp = sizeRange[1]; glPointSize(temp); LOGD("Point size is %f (can be between %f and %f)\n", temp, sizeRange[0], sizeRange[1]); GLfloat currentLineWidth; GLfloat widthRange[2]; glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth); glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, widthRange); temp = currentLineWidth+1; if (temp > widthRange[1]) temp = widthRange[1]; glLineWidth(temp); LOGD("Line width is %f (can be between %f and %f)\n", temp, widthRange[0], widthRange[1]); break; } case CATGL_KEY_MINUS: // decrease size of points and width of lines { GLfloat currentPtSize; GLfloat sizeRange[2]; glGetFloatv(GL_POINT_SIZE, ¤tPtSize); glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, sizeRange); GLfloat temp = currentPtSize-1; if (temp < sizeRange[0]) temp = sizeRange[0]; glPointSize(temp); LOGD("Point size is %f (can be between %f and %f)\n", temp, sizeRange[0], sizeRange[1]); GLfloat currentLineWidth; GLfloat widthRange[2]; glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth); glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, widthRange); temp = currentLineWidth-1; if (temp < widthRange[0]) temp = widthRange[0]; glLineWidth(temp); LOGD("Line width is %f (can be between %f and %f)\n", temp, widthRange[0], widthRange[1]); break; } } } if (s) { printf("-- %s\n", s); glDeleteBuffers(1, vbo); caUnloadObj(&m); load_obj(vbo, &m, s); } }