void GLAppMain::idle() { float ratio = (float)window_width / (float) window_height; projection.perspective(45,ratio,1,10000); vec3 lat = vec3(0,1,0)^lookat; lat.normalize(); // keyboard events if(keys[KEY_ESC]) exit(); if(keys[' ']){ goon = !goon; keys[' '] = 0; } if(keys[KEY_UP]) { pos += lookat*(50/fps); keys[KEY_UP] = 0; } if(keys[KEY_DOWN]) { pos -= lookat*(50/fps); keys[KEY_DOWN] = 0; } if(keys[KEY_LEFT]) { pos += lat*(50/fps); keys[KEY_LEFT] = 0; } if(keys[KEY_RIGHT]) { pos -= lat*(50/fps); keys[KEY_RIGHT] = 0; } static int look = 0; if(!look && mouse_button & BUTTON_LEFT) { setCursor(window_width / 2,window_height / 2); mouse_x = window_width / 2; mouse_y = window_height / 2; look = 1; } if(mouse_button & BUTTON_RIGHT) look = 0; if(look) { showCursor(0); mat3 m; m.rotate( lat, (mouse_y - window_height / 2) * 0.2 ); lookat = m*lookat; m.rotate_y( -(mouse_x - window_width / 2) * 0.2 ); lookat = m*lookat; setCursor(window_width / 2,window_height / 2); } else showCursor(1); vec3 up = lookat^lat; up.normalize(); modelview.look_at(pos,pos+lookat,up); }
void opengl_init(int w, int h) { /* init statue *********************************************************************************/ CLoad3DS g_Load3ds; t3DModel g_3DModel; shader_loader vs,ps; init_fbo(render_fbo, render_rt, true); init_fbo(blur_fbo, blur_rt, true); if(model_mesh.program == NULL) { LOGI("begin load shader"); model_mesh.program = new shader_program; if(!model_mesh.program->build(vs.load_shader_source("media/model.vs"),ps.load_shader_source("media/model.ps"))) { LOGI("build shader failed"); return; } model_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(model_mesh.program->get_program(),"rm_Vertex"); model_mesh.attribute_locations[static_mesh::NORMAL] = glGetAttribLocation(model_mesh.program->get_program(),"rm_Normal"); model_mesh.attribute_locations[static_mesh::TEXCOORD] = glGetAttribLocation(model_mesh.program->get_program(),"rm_TexCoord0"); LOGI("begin to load 3ds file"); g_Load3ds.Import3DS(&g_3DModel, "media/Radeon.3ds"); LOGI("load 3ds end"); t3DObject* p = &g_3DModel.pObject[0]; LOGI("---------- 0"); model_mesh.loc_view_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_matrix"); model_mesh.loc_view_proj_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_proj_matrix"); model_mesh.texs_locs[0] = glGetUniformLocation(model_mesh.program->get_program(), "base"); LOGI("---------- 1"); model_mesh.texs_idxs[0] = create_texture("media/Wood.tga"); LOGI("---------- 2"); glGenBuffers(4, model_mesh.attribute_vbos); LOGI("---------- 3"); glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW); LOGI("---------- 4"); glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::NORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pNormals[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::TEXCOORD]); glBufferData(GL_ARRAY_BUFFER, 4*2*p->numOfVerts, &(p->pTexVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW); LOGI("---------- 5"); model_mesh.num_faces = p->numOfFaces; } /* init background *********************************************************************************/ if(blur_mesh.program == NULL) { float *pos_data; GLushort *inds; GLuint num_ves; blur_mesh.program = new shader_program; if(!blur_mesh.program->build(vs.load_shader_source("media/quad.vs"),ps.load_shader_source("media/quad.ps"))) { LOGI("build shader failed"); return; } blur_mesh.texs_idxs[0] = render_rt; blur_mesh.texs_locs[0] = glGetUniformLocation(blur_mesh.program->get_program(), "RT"); shape::create_plane(1, &pos_data, NULL, NULL, &inds, num_ves); // blur_mesh.loc_view_proj_matrix = glGetUniformLocation(blur_mesh.program->get_program(), "view_proj_matrix"); blur_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(blur_mesh.program->get_program(),"rm_Vertex"); glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::POSITION]); glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::INDEX]); glBindBuffer(GL_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*2*3, inds, GL_STATIC_DRAW); blur_mesh.num_faces = 6; delete []pos_data; delete []inds; } if(combine_mesh.program == NULL) { float *pos_data; GLushort *inds; GLuint num_ves; combine_mesh = blur_mesh; combine_mesh.program = new shader_program; if(!combine_mesh.program->build(vs.load_shader_source("media/combine.vs"),ps.load_shader_source("media/combine.ps"))) { LOGI("build shader failed"); return; } combine_mesh.texs_idxs[0] = render_rt; combine_mesh.texs_locs[0] = glGetUniformLocation(combine_mesh.program->get_program(), "RT"); combine_mesh.texs_idxs[1] = blur_rt; combine_mesh.texs_locs[1] = glGetUniformLocation(combine_mesh.program->get_program(), "Blur1"); } glBindBuffer(GL_ARRAY_BUFFER, 0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); width = w; height = h; quad_proj_matrix.perspective(60, (float)w/h, 1.0f,3000.0f); }
void opengl_init(int w, int h) { /* init statue *********************************************************************************/ CLoad3DS g_Load3ds; t3DModel g_3DModel; shader_loader vs,ps; initFramebuffer(); if(torus_mesh.program == NULL) { LOGI("begin load shader"); torus_mesh.program = new shader_program; if(!torus_mesh.program->build(vs.load_shader_source("media/torus.vs"),ps.load_shader_source("media/torus.ps"))) { LOGI("build shader failed"); return; } torus_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(torus_mesh.program->get_program(),"rm_Vertex"); ; LOGI("begin to load 3ds file"); g_Load3ds.Import3DS(&g_3DModel, "media/Torus.3ds"); LOGI("load 3ds end"); t3DObject* p = &g_3DModel.pObject[0]; torus_mesh.loc_view_proj_matrix = glGetUniformLocation(torus_mesh.program->get_program(), "view_proj_matrix"); glGenBuffers(1, &torus_mesh.attribute_vbos[static_mesh::POSITION]); glGenBuffers(1, &torus_mesh.attribute_vbos[static_mesh::INDEX]); glBindBuffer(GL_ARRAY_BUFFER, torus_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, torus_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW); torus_mesh.num_faces = p->numOfFaces; } /* init background *********************************************************************************/ if(quad_mesh.program == NULL) { float *pos_data; GLushort *inds; GLuint num_ves; quad_mesh.program = new shader_program; if(!quad_mesh.program->build(vs.load_shader_source("media/quad.vs"),ps.load_shader_source("media/quad.ps"))) { LOGI("build shader failed"); return; } check_gl_error("build shader"); quad_mesh.texs_idxs[0] = texture; quad_mesh.texs_idxs[1] = create_texture("media/Flame.tga"); shape::create_plane(1, &pos_data, NULL, NULL, &inds, num_ves); // quad_mesh.loc_view_proj_matrix = glGetUniformLocation(quad_mesh.program->get_program(), "view_proj_matrix"); quad_mesh.texs_locs[0] = glGetUniformLocation(quad_mesh.program->get_program(), "RT"); quad_mesh.texs_locs[1] = glGetUniformLocation(quad_mesh.program->get_program(), "color"); quad_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(quad_mesh.program->get_program(),"rm_Vertex"); glGenBuffers(1, &quad_mesh.attribute_vbos[static_mesh::POSITION]); glGenBuffers(1, &quad_mesh.attribute_vbos[static_mesh::INDEX]); glBindBuffer(GL_ARRAY_BUFFER, quad_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*2*3, inds, GL_STATIC_DRAW); quad_mesh.num_faces = 6; delete []pos_data; delete []inds; } glBindBuffer(GL_ARRAY_BUFFER, 0); glDisable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); width = w; height = h; quad_proj_matrix.perspective(60, (float)w/h, 1.0f,3000.0f); }
void opengl_init(int w, int h) { /* init statue *********************************************************************************/ CLoad3DS g_Load3ds; t3DModel g_3DModel; shader_loader vs,ps; if(statue_mesh.program == NULL) { LOGI("begin load shader"); statue_mesh.program = new shader_program; if(!statue_mesh.program->build(vs.load_shader_source("media/statue.vs"),ps.load_shader_source("media/statue.ps"))) { LOGI("build shader failed"); return; } statue_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(statue_mesh.program->get_program(),"a_position"); statue_mesh.attribute_locations[static_mesh::TEXCOORD] = glGetAttribLocation(statue_mesh.program->get_program(),"a_texcoord"); statue_mesh.attribute_locations[static_mesh::NORMAL] = glGetAttribLocation(statue_mesh.program->get_program(),"a_normal"); LOGI("begin to load 3ds file"); g_Load3ds.Import3DS(&g_3DModel, "media/Hebe.3ds"); LOGI("load 3ds end"); t3DObject* p = &g_3DModel.pObject[0]; statue_mesh.texs_idxs[0] = create_texture("media/Rainbow.tga"); statue_mesh.texs_idxs[1] = create_cube_texture("media/Mars.dds"); statue_mesh.texs_locs[0] = glGetUniformLocation(statue_mesh.program->get_program(),"s_diffuse"); statue_mesh.texs_locs[1] = glGetUniformLocation(statue_mesh.program->get_program(),"s_enviroment"); statue_mesh.wvp_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_wvp"); statue_mesh.world_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_world_mat"); statue_mesh.env_inv_world_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_env_inv_world"); statue_mesh.eye_loc = glGetUniformLocation(statue_mesh.program->get_program(), "eye"); glGenBuffers(4, statue_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::TEXCOORD]); glBufferData(GL_ARRAY_BUFFER, 4*2*p->numOfVerts, &(p->pTexVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::NORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pNormals[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW); statue_mesh.num_faces = p->numOfFaces; } /* init background *********************************************************************************/ if(background_mesh.program == NULL) { float *pos_data, *tex_data, *normal_data; GLushort *inds; GLuint num_ves; background_mesh.program = new shader_program; if(!background_mesh.program->build(vs.load_shader_source("media/background.vs"),ps.load_shader_source("media/background.ps"))) { LOGI("build shader failed"); return; } shape::create_cube(1000.0f, &pos_data, NULL, NULL, &inds, num_ves); background_mesh.wvp_loc = glGetUniformLocation(background_mesh.program->get_program(), "u_matViewProjection"); background_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(background_mesh.program->get_program(),"a_position"); glGenBuffers(4, background_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, background_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, background_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12*2*3, inds, GL_STATIC_DRAW); background_mesh.texs_locs[0] = glGetUniformLocation(background_mesh.program->get_program(),"s_enviroment"); background_mesh.texs_idxs[0] = statue_mesh.texs_idxs[1]; background_mesh.num_faces = 12; delete []pos_data; delete []inds; } glBindBuffer(GL_ARRAY_BUFFER, 0); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0,0,w,h); projection.perspective(60, (float)w/h, 1.0f,3000.0f); }
void opengl_init(int w, int h) { /**********************************************************************************/ CLoad3DS g_Load3ds; t3DModel g_3DModel; shader_loader vs,ps; /*object**********************************************************************************/ object_program.p_program = new shader_program; if(!object_program.p_program->build(vs.load_shader_source("media/obj.vs"), ps.load_shader_source("media/obj.ps"))) { LOGI("build shader failed\n"); return; } object_program.attribute_locations[POSITION] = glGetAttribLocation(object_program.p_program->get_program(),"rm_Vertex"); object_program.attribute_locations[NORMAL] = glGetAttribLocation(object_program.p_program->get_program(),"rm_Normal"); object_program.attribute_locations[TEXCOORD] = glGetAttribLocation(object_program.p_program->get_program(),"rm_TexCoord0"); object_program.attribute_locations[TARGENT] = glGetAttribLocation(object_program.p_program->get_program(),"rm_Tangent"); object_program.attribute_locations[BINORMAL] = glGetAttribLocation(object_program.p_program->get_program(),"rm_Binormal"); object_program.loc_world_view_proj = glGetUniformLocation(object_program.p_program->get_program(), "world_view_proj_mat"); object_program.loc_light_pos = glGetUniformLocation(object_program.p_program->get_program(), "lightPos"); object_program.loc_light_dir = glGetUniformLocation(object_program.p_program->get_program(), "lightDir"); object_program.loc_view_pos = glGetUniformLocation(object_program.p_program->get_program(), "view_position"); object_program.texs_locs[0] = glGetUniformLocation(object_program.p_program->get_program(), "BumpMap"); object_program.texs_locs[1] = glGetUniformLocation(object_program.p_program->get_program(), "ObjectMap"); /* object mesh *****************************************************************************************/ LOGI("begin to load 3ds file"); g_Load3ds.Import3DS(&g_3DModel, "media/Teapot.3ds"); LOGI("load 3ds end"); if(g_3DModel.numOfObjects == 0) { return; } t3DObject* p = &g_3DModel.pObject[0]; texture_obj = create_texture("media/Fieldstone.tga"); texture_bump = create_texture("media/FieldstoneBumpDOT3.tga"); vec3* targents = new vec3[p->numOfVerts]; vec3* binormal = new vec3[p->numOfVerts]; computer_targent_space((vec3*)p->pNormals, (vec3*)p->pVerts, targents, binormal, (float*)p->pTexVerts, p->pFaces->vertIndex, p->numOfVerts, p->numOfFaces); glGenBuffers(6, object_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, object_mesh.attribute_vbos[TEXCOORD]); glBufferData(GL_ARRAY_BUFFER, 4*2*p->numOfVerts, &(p->pTexVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, object_mesh.attribute_vbos[POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, object_mesh.attribute_vbos[NORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pNormals[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, object_mesh.attribute_vbos[TARGENT]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(targents[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, object_mesh.attribute_vbos[BINORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(binormal[0].x), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object_mesh.attribute_vbos[INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW); object_mesh.num_faces = p->numOfFaces; glBindBuffer(GL_ARRAY_BUFFER, 0); glEnable(GL_DEPTH_TEST); glViewport(0,0,w,h); width = w; height = h; proj_matrix.perspective(60, (float)w/h, 1.0f,3000.0f); }
void opengl_init(int w, int h) { /* init statue *********************************************************************************/ shader_loader vs,ps; if(statue_mesh.program == NULL) { LOGI("begin load shader"); statue_mesh.program = new shader_program; if(!statue_mesh.program->build(vs.load_shader_source("media/statue.vs"),ps.load_shader_source("media/statue.ps"))) { LOGI("build shader failed"); return; } statue_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(statue_mesh.program->get_program(),"a_position"); statue_mesh.attribute_locations[static_mesh::TEXCOORD] = glGetAttribLocation(statue_mesh.program->get_program(),"a_texcoord"); statue_mesh.attribute_locations[static_mesh::NORMAL] = glGetAttribLocation(statue_mesh.program->get_program(),"a_normal"); float* normal, *pos, *texcoord; unsigned short* indxs; GLuint num_vers, num_indx; num_indx = shape::create_sphere(20, 15.0, &pos, &normal, &texcoord, &indxs, num_vers); statue_mesh.texs_idxs[0] = create_texture("media/Rainbow.tga"); statue_mesh.texs_idxs[1] = create_cube_texture("media/Snow.dds"); statue_mesh.texs_locs[0] = glGetUniformLocation(statue_mesh.program->get_program(),"s_diffuse"); statue_mesh.texs_locs[1] = glGetUniformLocation(statue_mesh.program->get_program(),"s_enviroment"); statue_mesh.wvp_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_wvp"); statue_mesh.world_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_world_mat"); statue_mesh.env_inv_world_loc = glGetUniformLocation(statue_mesh.program->get_program(), "u_env_inv_world"); statue_mesh.eye_loc = glGetUniformLocation(statue_mesh.program->get_program(), "eye"); glGenBuffers(4, statue_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::TEXCOORD]); glBufferData(GL_ARRAY_BUFFER, 4*2*num_vers, texcoord, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*num_vers, pos, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::NORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*num_vers, normal, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, statue_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*num_indx, indxs, GL_STATIC_DRAW); statue_mesh.num_faces = num_indx/3; } /* init background *********************************************************************************/ if(background_mesh.program == NULL) { float *pos_data, *tex_data, *normal_data; GLushort *inds; GLuint num_ves; background_mesh.program = new shader_program; if(!background_mesh.program->build(vs.load_shader_source("media/background.vs"),ps.load_shader_source("media/background.ps"))) { LOGI("build shader failed"); return; } shape::create_cube(1000.0f, &pos_data, NULL, NULL, &inds, num_ves); background_mesh.wvp_loc = glGetUniformLocation(background_mesh.program->get_program(), "u_matViewProjection"); background_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(background_mesh.program->get_program(),"a_position"); glGenBuffers(4, background_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, background_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, background_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12*2*3, inds, GL_STATIC_DRAW); background_mesh.texs_locs[0] = glGetUniformLocation(background_mesh.program->get_program(),"s_enviroment"); background_mesh.texs_idxs[0] = statue_mesh.texs_idxs[1]; background_mesh.num_faces = 12; delete []pos_data; delete []inds; } glBindBuffer(GL_ARRAY_BUFFER, 0); glEnable(GL_DEPTH_TEST); glViewport(0,0,w,h); projection.perspective(60, (float)w/h, 1.0f,3000.0f); }
void opengl_init(int w, int h) { /* init statue *********************************************************************************/ LOGI("begin load shader"); shader_loader vs, ps; earth_mesh.program = new shader_program; if(!earth_mesh.program->build(vs.load_shader_source("media/earth.vs"),ps.load_shader_source("media/earth.ps"))) { LOGI("build shader failed"); return; } earth_mesh.texs_idxs[0] = create_texture("media/Earth.tga"); earth_mesh.texs_idxs[1] = create_texture("media/EarthNight.tga"); earth_mesh.texs_idxs[2] = create_texture("media/EarthClouds.tga"); earth_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(earth_mesh.program->get_program(),"rm_Vertex"); earth_mesh.attribute_locations[static_mesh::NORMAL] = glGetAttribLocation(earth_mesh.program->get_program(),"rm_Normal"); earth_mesh.attribute_locations[static_mesh::TEXCOORD] = glGetAttribLocation(earth_mesh.program->get_program(),"rm_TexCoord0"); earth_mesh.loc_world_view_matrix = glGetUniformLocation(earth_mesh.program->get_program(), "world_view_matrix"); earth_mesh.loc_world_view_proj_matrix = glGetUniformLocation(earth_mesh.program->get_program(), "world_view_proj_matrix"); earth_mesh.loc_cos_time = glGetUniformLocation(earth_mesh.program->get_program(),"cos_time_0_2PI"); earth_mesh.loc_sin_time = glGetUniformLocation(earth_mesh.program->get_program(),"sin_time_0_2PI"); earth_mesh.texs_locs[0] = glGetUniformLocation(earth_mesh.program->get_program(),"EarthDay"); earth_mesh.texs_locs[1] = glGetUniformLocation(earth_mesh.program->get_program(),"EarthNight"); earth_mesh.texs_locs[2] = glGetUniformLocation(earth_mesh.program->get_program(),"EarthCloudGloss"); float*pos, *normal, *texcoord; unsigned short *indx; GLuint num_vertexs; GLuint num_index; num_index = shape::create_sphere(60,20, &pos, &normal, &texcoord, &indx, num_vertexs); glGenBuffers(4, earth_mesh.attribute_vbos); glBindBuffer(GL_ARRAY_BUFFER, earth_mesh.attribute_vbos[static_mesh::POSITION]); glBufferData(GL_ARRAY_BUFFER, 4*3*num_vertexs, pos, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, earth_mesh.attribute_vbos[static_mesh::NORMAL]); glBufferData(GL_ARRAY_BUFFER, 4*3*num_vertexs, normal, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, earth_mesh.attribute_vbos[static_mesh::TEXCOORD]); glBufferData(GL_ARRAY_BUFFER, 4*2*num_vertexs, texcoord, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, earth_mesh.attribute_vbos[static_mesh::INDEX]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*num_index, indx, GL_STATIC_DRAW); earth_mesh.num_faces = num_index/3; delete []pos; delete []normal; delete []texcoord; delete []indx; glEnable(GL_DEPTH_TEST); projection_matrix.perspective(90.f, (float)w/h, 1.f, 3000.f); }