void update() { YUVBuffer yuv; // yuv_buffer_try_lock(...) returns false if the last read frame is // still up to date, in this case we can simply retender the // last frame without an update // We don't need to call unlock unless the lock operation was successfull if(!ogg.yuv_buffer_try_lock(&yuv)) return; // Create the textures if needed, at this point we // know how big the textures should be. // The sample plyer that comes with the official SDK // assummes uv_width=y_width/2 , uv_height=y_height/2 // but I'm not sure whether that is always true if(-1==y_tex){ y_tex = gen_texture(yuv.y_width,yuv.y_height); u_tex = gen_texture(yuv.uv_width,yuv.uv_height); v_tex = gen_texture(yuv.uv_width,yuv.uv_height); } int y_offset = ogg.offset_x() + yuv.y_stride * ogg.offset_y(); int uv_offset = ogg.offset_x()/(yuv.y_width/yuv.uv_width)+ yuv.uv_stride * ogg.offset_y()/(yuv.y_height/yuv.uv_height); update_texture(y_tex,yuv.y+y_offset,yuv.y_width,yuv.y_height,yuv.y_stride); update_texture(u_tex,yuv.u+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride); update_texture(v_tex,yuv.v+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride); ogg.yuv_buffer_unlock(); }
static void init_flare_stream (flare_stream *s, int num_flares, float bx, float by, float bz, float speed) { int i; s->flares = (Vector *) calloc (num_flares, sizeof (Vector)); s->num_flares = num_flares; s->flare_tex = gen_texture(); s->speed = speed; for (i = 0; i != s->num_flares; i++) { s->flares[i].x = -800.0f * random() / RAND_MAX - 1150 + bx; s->flares[i].y = 10.0f * random() / RAND_MAX - 20 + by; s->flares[i].z = 10.0f * random() / RAND_MAX - 20 + bz; } }
bool Texture::load( const std::string& filaname ) { Ref ref; // Reference to the Item we'll be working on. // We only need to reset if we're referencing a texture. if( key.size() ) { reset(); } key = filaname; ref = get_ref(); // If this Item already exists, and is loaded, we're all set. if( ref != -1u && ref < registery.size() && registery[ref].refCount++ != 0 ) return true; // Otherwise, make it. registery.push_back( Item(key,0,1) ); ref = registery.size() - 1; glGenTextures( 1, ®istery[ref].glHandle ); // Use SDL to lead the image for simplicity. SDL_Surface* sdlSurface = SDL_LoadBMP( filaname.c_str() ); if( sdlSurface ) { gen_texture( registery[ref].glHandle, sdlSurface ); SDL_FreeSurface( sdlSurface ); ok = true; } else { ok = false; } return ok; }
TextureData* load_bmp(const char* path, const TextureFmt* fmt) { TextureData* tex; SDL_Surface* surf = SDL_LoadBMP(path); if (!surf) throw Core::SolidDescentException("Could not read texture file"); // verify that both width & height are powers of 2 if ((surf->w & (surf->w - 1)) != 0 || (surf->h & (surf->h - 1)) != 0) { SDL_FreeSurface(surf); throw Core::SolidDescentException("Texture size is not a power of two"); } // verify that the texture is in 24-bpp format if (surf->format->BitsPerPixel != 24) { SDL_FreeSurface(surf); throw Core::SolidDescentException("Texture is of unsupported format"); } GLuint handle = gen_texture(fmt); tex = new TextureData(handle, surf->w, surf->h); // Annoying surface has a flipped y-axis, so let's flip it again... :| int bytes = surf->format->BitsPerPixel / 8; char* pixels = new char[surf->w * surf->h * bytes]; for (int y = 0; y < surf->h; ++y) { for (int x = 0; x < surf->w; ++x) { for (int i = 0; i < bytes; ++i) pixels[(x + (y * surf->w)) * bytes + i] = ((char*) (surf->pixels))[(x + ((surf->h - y - 1) * surf->w)) * bytes + i]; } } SDL_FreeSurface(surf); glTexImage2D(GL_TEXTURE_2D, 0, fmt->fmt, tex->height, tex->width, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixels); delete [] pixels; return tex; }
bool load_game(int width, int height) { window_width = width; window_height = height; if (!shader_default.load_from_file("./default.vs", "./default.fs") || !shader_dither.load_from_file("./dither.vs", "./dither.fs")) return false; //if (!load_mesh_indexed(mesh_teapot, "../../../resources/models/crytek-sponza/sponza.obj")) // return false; if (!load_mesh_indexed(mesh_teapot, "../data/models/teapot.obj")) return false; uint8 dither_pattern[] = { 255, 0, 255, 0 }; tex_dither = gen_texture(dither_pattern, 2, 2, GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST); mesh_quad = Primitive::tex_quad(); return true; }
void GLCanvas::initializeGL() { glewInit(); //std::cout << this->format().majorVersion() << "." << this->format().minorVersion() <<std::endl; //std::cout << glGetString(GL_VERSION)<<std::endl; glClearColor(0, 0, 0, 0); test_program.addShaderFromSourceFile(QGLShader::Vertex, "C:\\Users\\Fernando\\Desenvolvimento\\CSGMod\\test.vert"); test_program.addShaderFromSourceFile(QGLShader::Fragment, "C:\\Users\\Fernando\\Desenvolvimento\\CSGMod\\test.frag"); test_program.bindAttributeLocation( "in_Position", 0 ); test_program.bindAttributeLocation( "in_Color", 1 ); test_program.bindAttributeLocation( "scene_data", 2 ); if ( test_program.link() ) { //std::cout << "Binding shader program." << std::endl; test_program.bind(); //std::cout << "in_Position:" << test_program.attributeLocation("in_Position"); //std::cout << "in_Color:" << test_program.attributeLocation("in_Color"); } else { //std::cout << "Error compiling/linking" << test_program.log().toStdString(); } if ( position_buffer.create() ) { //std::cout << "\nCreated position buffer\n"; } if ( position_buffer.bind() ) { //std::cout << "\nposition buffer bound\n"; } position_buffer.allocate( in_pos, sizeof(GLfloat)*18 ); if ( color_buffer.create() ) { //std::cout << "\nCreated color_buffer buffer\n"; } if ( color_buffer.bind() ) { //std::cout << "\ncolor buffer bound\n"; } color_buffer.allocate( in_col, sizeof(GLfloat)*18 ); if ( position_buffer.bind() ) { //std::cout << "\n2position buffer bound\n"; } test_program.enableAttributeArray(0); test_program.setAttributeBuffer(0, GL_FLOAT, 0, 3); if ( color_buffer.bind() ) { //std::cout << "\n2color buffer bound\n"; } test_program.enableAttributeArray(1); test_program.setAttributeBuffer(1, GL_FLOAT, 0, 3); GLfloat *temp = (GLfloat *)position_buffer.map (QGLBuffer::ReadWrite); for (int i = 0; i < 18; i++ ) { //std::cout << "Position " << i << ": " << temp[i] << std::endl; } position_buffer.unmap(); GLfloat *temp2 = (GLfloat *)color_buffer.map (QGLBuffer::ReadWrite); for (int i = 0; i < 18; i++ ) { //std::cout << "Color " << i << ": " << temp2[i] << std::endl; } color_buffer.unmap(); test_program.setUniformValue( test_program.uniformLocation("scene_data"), 0); // Texture Unit 0 // Stream texture gen_texture(); }
static void init(ModeInfo *mi) { static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; static const GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; static const GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; projectiveplanestruct *pp = &projectiveplane[MI_SCREEN(mi)]; if (walk_speed == 0.0) walk_speed = 20.0; if (view == VIEW_TURN) { pp->alpha = frand(360.0); pp->beta = frand(360.0); pp->delta = frand(360.0); pp->zeta = 0.0; pp->eta = 0.0; pp->theta = 0.0; } else { pp->alpha = 0.0; pp->beta = 0.0; pp->delta = 0.0; pp->zeta = 120.0; pp->eta = 180.0; pp->theta = 90.0; } pp->umove = frand(2.0*M_PI); pp->vmove = frand(2.0*M_PI); pp->dumove = 0.0; pp->dvmove = 0.0; pp->side = 1; if (sin(walk_direction*M_PI/180.0) >= 0.0) pp->dir = 1; else pp->dir = -1; pp->offset4d[0] = 0.0; pp->offset4d[1] = 0.0; pp->offset4d[2] = 0.0; pp->offset4d[3] = 1.2; pp->offset3d[0] = 0.0; pp->offset3d[1] = 0.0; pp->offset3d[2] = -1.2; pp->offset3d[3] = 0.0; gen_texture(mi); setup_projective_plane(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); if (marks) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (projection_3d == DISP_3D_PERSPECTIVE || view == VIEW_WALK || view == VIEW_WALKTURN) { if (view == VIEW_WALK || view == VIEW_WALKTURN) gluPerspective(60.0,1.0,0.01,10.0); else gluPerspective(60.0,1.0,0.1,10.0); } else { glOrtho(-0.6,0.6,-0.6,0.6,0.1,10.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); # ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ if (display_mode == DISP_WIREFRAME) display_mode = DISP_SURFACE; # endif if (display_mode == DISP_SURFACE) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); glDepthMask(GL_TRUE); glDisable(GL_BLEND); } else if (display_mode == DISP_TRANSPARENT) { glDisable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); } else /* display_mode == DISP_WIREFRAME */ { glDisable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_BLEND); } }