C++ (Cpp) glRenderbufferStorage Examples - HotExamples

文章推薦指數: 80 %
投票人數:10人

These are the top rated real world C++ (Cpp) examples of glRenderbufferStorage extracted from open source projects. You can rate examples to help us improve the ... Togglenavigation HotExamplesENENRUDEFRESPTITJPZH C++PHPC#JavaGoC++PythonJSTS SearchC++(Cpp)glRenderbufferStorageExamplesC++(Cpp)glRenderbufferStorage-30examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglRenderbufferStorageextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glRenderbufferStorageExamplesathotexamples.com:30reportthisadRelatedget_dtypesqlite3_column_typeFlCheckForAsciibackgroundRolegtk_entry_completion_newcommit_list_insertcpu_loop_exitrb_obj_taintZOLTAN_MALLOCtimer_createreportthisadRelatedinlangsezAdmin_Team(PHP)populate_vendors(PHP)IconInfo(C#)Album(C#)NewDocumentMapping(Go)Index(Go)CountryExtended(Java)ICFBamSwingTokenDefJPanelCommon(Java)univariate_kf(Python)quick_age_function(Python)reportthisadExample#10ShowfileFile: CCRenderTexture.cpp Project: cheerayhuang/cocos2d-xboolCCRenderTexture::initWithWidthAndHeight(intw,inth,CCTexture2DPixelFormateFormat,GLuintuDepthStencilFormat) { CCAssert(eFormat!=kCCTexture2DPixelFormat_A8,"onlyRGBandRGBAformatsarevalidforarendertexture"); boolbRet=false; void*data=NULL; do { w=(int)(w*CC_CONTENT_SCALE_FACTOR()); h=(int)(h*CC_CONTENT_SCALE_FACTOR()); glGetIntegerv(GL_FRAMEBUFFER_BINDING,&m_nOldFBO); //texturesmustbepoweroftwosquared unsignedintpowW=0; unsignedintpowH=0; if(CCConfiguration::sharedConfiguration()->supportsNPOT()) { powW=w; powH=h; } else { powW=ccNextPOT(w); powH=ccNextPOT(h); } data=malloc((int)(powW*powH*4)); CC_BREAK_IF(!data); memset(data,0,(int)(powW*powH*4)); m_ePixelFormat=eFormat; m_pTexture=newCCTexture2D(); if(m_pTexture) { m_pTexture->initWithData(data,(CCTexture2DPixelFormat)m_ePixelFormat,powW,powH,CCSizeMake((float)w,(float)h)); } else { break; } GLintoldRBO; glGetIntegerv(GL_RENDERBUFFER_BINDING,&oldRBO); if(CCConfiguration::sharedConfiguration()->checkForGLExtension("GL_QCOM")) { m_pTextureCopy=newCCTexture2D(); if(m_pTextureCopy) { m_pTextureCopy->initWithData(data,(CCTexture2DPixelFormat)m_ePixelFormat,powW,powH,CCSizeMake((float)w,(float)h)); } else { break; } } //generateFBO glGenFramebuffers(1,&m_uFBO); glBindFramebuffer(GL_FRAMEBUFFER,m_uFBO); //associatetexturewithFBO glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_pTexture->getName(),0); if(uDepthStencilFormat!=0) { //createandattachdepthbuffer glGenRenderbuffers(1,&m_uDepthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER,m_uDepthRenderBufffer); glRenderbufferStorage(GL_RENDERBUFFER,uDepthStencilFormat,(GLsizei)powW,(GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_uDepthRenderBufffer); //ifdepthformatistheonewithstencilpart,bindsamerenderbufferasstencilattachment if(uDepthStencilFormat==GL_DEPTH24_STENCIL8) { glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,m_uDepthRenderBufffer); } } //checkifitworked(probablyworthdoing:)) CCAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE,"Couldnotattachtexturetoframebuffer"); m_pTexture->setAliasTexParameters(); //retained setSprite(CCSprite::createWithTexture(m_pTexture)); m_pTexture->release(); m_pSprite->setScaleY(-1); ccBlendFunctBlendFunc={GL_ONE,GL_ONE_MINUS_SRC_ALPHA}; m_pSprite->setBlendFunc(tBlendFunc); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,m_nOldFBO); //Diabledbydefault. m_bAutoDraw=false; //addspriteforbackwardcompatibility addChild(m_pSprite); bRet=true; }while(0); CC_SAFE_FREE(data); returnbRet; }Example#20ShowfileFile: deferred_shading.cpp Project: 2015winter/LearnOpenGL//TheMAINfunction,fromherewestartourapplicationandrunourGameloop intmain() { //InitGLFW glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3); glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); GLFWwindow*window=glfwCreateWindow(SCR_WIDTH,SCR_HEIGHT,"LearnOpenGL",nullptr,nullptr);//Windowed glfwMakeContextCurrent(window); //Settherequiredcallbackfunctions glfwSetKeyCallback(window,key_callback); glfwSetCursorPosCallback(window,mouse_callback); glfwSetScrollCallback(window,scroll_callback); //Options glfwSetInputMode(window,GLFW_CURSOR,GLFW_CURSOR_DISABLED); //InitializeGLEWtosetuptheOpenGLFunctionpointers glewExperimental=GL_TRUE; glewInit(); //Definetheviewportdimensions glViewport(0,0,SCR_WIDTH,SCR_HEIGHT); //SetupsomeOpenGLoptions glEnable(GL_DEPTH_TEST); //Setupandcompileourshaders ShadershaderGeometryPass("g_buffer.vs","g_buffer.frag"); ShadershaderLightingPass("deferred_shading.vs","deferred_shading.frag"); ShadershaderLightBox("deferred_light_box.vs","deferred_light_box.frag"); //Setsamplers shaderLightingPass.Use(); glUniform1i(glGetUniformLocation(shaderLightingPass.Program,"gPosition"),0); glUniform1i(glGetUniformLocation(shaderLightingPass.Program,"gNormal"),1); glUniform1i(glGetUniformLocation(shaderLightingPass.Program,"gAlbedoSpec"),2); //Models Modelcyborg(FileSystem::getPath("resources/objects/nanosuit/nanosuit.obj").c_str()); std::vector<:vec3>objectPositions; objectPositions.push_back(glm::vec3(-3.0,-3.0,-3.0)); objectPositions.push_back(glm::vec3(0.0,-3.0,-3.0)); objectPositions.push_back(glm::vec3(3.0,-3.0,-3.0)); objectPositions.push_back(glm::vec3(-3.0,-3.0,0.0)); objectPositions.push_back(glm::vec3(0.0,-3.0,0.0)); objectPositions.push_back(glm::vec3(3.0,-3.0,0.0)); objectPositions.push_back(glm::vec3(-3.0,-3.0,3.0)); objectPositions.push_back(glm::vec3(0.0,-3.0,3.0)); objectPositions.push_back(glm::vec3(3.0,-3.0,3.0)); //-Colors constGLuintNR_LIGHTS=32; std::vector<:vec3>lightPositions; std::vector<:vec3>lightColors; srand(13); for(GLuinti=0;i(std::sqrt(linear*linear-4*quadratic*(constant-(256.0/lightThreshold)*maxBrightness))))/(2*quadratic); glUniform1f(glGetUniformLocation(shaderLightingPass.Program,("lights["+std::to_string(i)+"].Radius").c_str()),radius); } glUniform3fv(glGetUniformLocation(shaderLightingPass.Program,"viewPos"),1,&camera.Position[0]); glUniform1i(glGetUniformLocation(shaderLightingPass.Program,"draw_mode"),draw_mode); RenderQuad(); //2.5.Copycontentofgeometry'sdepthbuffertodefaultframebuffer'sdepthbuffer glBindFramebuffer(GL_READ_FRAMEBUFFER,gBuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);//Writetodefaultframebuffer //blittodefaultframebuffer.NotethatthismayormaynotworkastheinternalformatsofboththeFBOanddefaultframebufferhavetomatch. //theinternalformatsareimplementationdefined.Thisworksonallofmysystems,butifitdoesn'tonyoursyou'lllikelyhavetowritetothe //depthbufferinanotherstage(orsomehowseetomatchthedefaultframebuffer'sinternalformatwiththeFBO'sinternalformat). glBlitFramebuffer(0,0,SCR_WIDTH,SCR_HEIGHT,0,0,SCR_WIDTH,SCR_HEIGHT,GL_DEPTH_BUFFER_BIT,GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER,0); //3.Renderlightsontopofscene,byblitting shaderLightBox.Use(); glUniformMatrix4fv(glGetUniformLocation(shaderLightBox.Program,"projection"),1,GL_FALSE,glm::value_ptr(projection)); glUniformMatrix4fv(glGetUniformLocation(shaderLightBox.Program,"view"),1,GL_FALSE,glm::value_ptr(view)); for(GLuinti=0;isetBlendFunc(tBlendFunc); this->addSubview(imageView); this->setImageView(imageView); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,m_nOldFBO); //Diabledbydefault. m_bAutoDraw=false; bRet=true; }while(0); CC_SAFE_FREE(data); returnbRet; }Example#50ShowfilevoidQGLFramebufferObjectPrivate::init(QGLFramebufferObject*q,constQSize&sz, QGLFramebufferObject::Attachmentattachment, GLenumtexture_target,GLenuminternal_format,GLintsamples) { QGLContext*ctx=const_cast(QGLContext::currentContext()); fbo_guard.setContext(ctx); boolext_detected=(QGLExtensions::glExtensions()&QGLExtensions::FramebufferObject); if(!ext_detected||(ext_detected&&!qt_resolve_framebufferobject_extensions(ctx))) return; size=sz; target=texture_target; //texturedimensions QT_RESET_GLERROR();//reseterrorstate GLuintfbo=0; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER_EXT,fbo); fbo_guard.setId(fbo); glDevice.setFBO(q,attachment); QT_CHECK_GLERROR(); //inittexture if(samples==0){ glGenTextures(1,&texture); glBindTexture(target,texture); glTexImage2D(target,0,internal_format,size.width(),size.height(),0, GL_RGBA,GL_UNSIGNED_BYTE,NULL); #ifndefQT_OPENGL_ES glTexParameteri(target,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(target,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(target,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); #else glTexParameterf(target,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(target,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(target,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); #endif glFramebufferTexture2D(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, target,texture,0); QT_CHECK_GLERROR(); valid=checkFramebufferStatus(); glBindTexture(target,0); color_buffer=0; }else{ GLintmaxSamples; glGetIntegerv(GL_MAX_SAMPLES_EXT,&maxSamples); samples=qBound(1,int(samples),int(maxSamples)); glGenRenderbuffers(1,&color_buffer); glBindRenderbuffer(GL_RENDERBUFFER_EXT,color_buffer); if(glRenderbufferStorageMultisampleEXT){ glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples, internal_format,size.width(),size.height()); }else{ samples=0; glRenderbufferStorage(GL_RENDERBUFFER_EXT,internal_format, size.width(),size.height()); } glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT,color_buffer); QT_CHECK_GLERROR(); valid=checkFramebufferStatus(); if(valid) glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,GL_RENDERBUFFER_SAMPLES_EXT,&samples); } if(attachment==QGLFramebufferObject::CombinedDepthStencil &&(QGLExtensions::glExtensions()&QGLExtensions::PackedDepthStencil)){ //depthandstencilbufferneedsanotherextension glGenRenderbuffers(1,&depth_stencil_buffer); Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer)); glBindRenderbuffer(GL_RENDERBUFFER_EXT,depth_stencil_buffer); Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer)); if(samples!=0&&glRenderbufferStorageMultisampleEXT) glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples, GL_DEPTH24_STENCIL8_EXT,size.width(),size.height()); else glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,size.width(),size.height()); GLinti=0; glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,GL_RENDERBUFFER_DEPTH_SIZE_EXT,&i); glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,depth_stencil_buffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,depth_stencil_buffer); fbo_attachment=QGLFramebufferObject::CombinedDepthStencil; valid=checkFramebufferStatus(); if(!valid) glDeleteRenderbuffers(1,&depth_stencil_buffer); }elseif(attachment==QGLFramebufferObject::Depth ||attachment==QGLFramebufferObject::CombinedDepthStencil) { glGenRenderbuffers(1,&depth_stencil_buffer); Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer)); glBindRenderbuffer(GL_RENDERBUFFER_EXT,depth_stencil_buffer); Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer)); if(samples!=0&&glRenderbufferStorageMultisampleEXT){ #ifdefQT_OPENGL_ES #defineGL_DEPTH_COMPONENT160x81A5 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples, GL_DEPTH_COMPONENT16,size.width(),size.height()); #else glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples, GL_DEPTH_COMPONENT,size.width(),size.height()); #endif }else{ #ifdefQT_OPENGL_ES #defineGL_DEPTH_COMPONENT160x81A5 glRenderbufferStorage(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT16,size.width(),size.height()); #else glRenderbufferStorage(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT,size.width(),size.height()); #endif } GLinti=0; glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,GL_RENDERBUFFER_DEPTH_SIZE_EXT,&i); glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,depth_stencil_buffer); fbo_attachment=QGLFramebufferObject::Depth; valid=checkFramebufferStatus(); if(!valid) glDeleteRenderbuffers(1,&depth_stencil_buffer); }else{ fbo_attachment=QGLFramebufferObject::NoAttachment; } glBindFramebuffer(GL_FRAMEBUFFER_EXT,ctx->d_ptr->current_fbo); if(!valid){ if(color_buffer) glDeleteRenderbuffers(1,&color_buffer); else glDeleteTextures(1,&texture); glDeleteFramebuffers(1,&fbo); fbo_guard.setId(0); } QT_CHECK_GLERROR(); format.setTextureTarget(target); format.setSamples(int(samples)); format.setAttachment(fbo_attachment); format.setInternalTextureFormat(internal_format); }Example#60ShowfileFile: fbo-viewport.c Project: ThirteenFish/piglitenumpiglit_result piglit_display(void) { GLubyte*win_image,*fbo_image; GLuintfbo,rb; boolpass=true; win_image=(GLubyte*)malloc(piglit_width*piglit_height*3); fbo_image=(GLubyte*)malloc(piglit_width*piglit_height*3); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, piglit_width,piglit_height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb); assert(glGetError()==0); assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)== GL_FRAMEBUFFER_COMPLETE_EXT); /*drawreferenceimageinthewindow*/ glBindFramebuffer(GL_FRAMEBUFFER,piglit_winsys_fbo); draw_test_image(); glReadPixels(0,0,piglit_width,piglit_height, GL_RGB,GL_UNSIGNED_BYTE,win_image); /*drawtestimageinfbo*/ glBindFramebuffer(GL_FRAMEBUFFER,fbo); glReadBuffer(GL_COLOR_ATTACHMENT0); draw_test_image(); glReadPixels(0,0,piglit_width,piglit_height, GL_RGB,GL_UNSIGNED_BYTE,fbo_image); /*compareimages*/ if(memcmp(win_image,fbo_image,piglit_width*piglit_height*3)){ #if0/*helpfuldebugcode*/ inti,k; for(i=k=0;itextures,gl->hw_render_fbo); depth=hwr->depth; stencil=hwr->stencil; #ifdefHAVE_OPENGLES if(!gl_check_capability(GL_CAPS_PACKED_DEPTH_STENCIL)) returnfalse; RARCH_LOG("[GL]:SupportsPackeddepthstencil.\n"); #endif if(depth) { glGenRenderbuffers(gl->textures,gl->hw_render_depth); gl->hw_render_depth_init=true; } for(i=0;itextures;i++) { glBindFramebuffer(RARCH_GL_FRAMEBUFFER,gl->hw_render_fbo[i]); glFramebufferTexture2D(RARCH_GL_FRAMEBUFFER, RARCH_GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,gl->texture[i],0); if(depth) { glBindRenderbuffer(RARCH_GL_RENDERBUFFER,gl->hw_render_depth[i]); glRenderbufferStorage(RARCH_GL_RENDERBUFFER, stencil?RARCH_GL_DEPTH24_STENCIL8:GL_DEPTH_COMPONENT16, width,height); glBindRenderbuffer(RARCH_GL_RENDERBUFFER,0); if(stencil) { #ifdefined(HAVE_OPENGLES2)||defined(HAVE_OPENGLES1)||((defined(__MACH__)&&(defined(__ppc__)||defined(__ppc64__)))) /*GLES2isabitweird,asalways. *There'snoGL_DEPTH_STENCIL_ATTACHMENTlikeindesktopGL.*/ glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER, RARCH_GL_DEPTH_ATTACHMENT, RARCH_GL_RENDERBUFFER,gl->hw_render_depth[i]); glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER, RARCH_GL_STENCIL_ATTACHMENT, RARCH_GL_RENDERBUFFER,gl->hw_render_depth[i]); #else /*WeuseARBFBOextensions,noneedtocheck.*/ glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, RARCH_GL_RENDERBUFFER,gl->hw_render_depth[i]); #endif } else { glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER, RARCH_GL_DEPTH_ATTACHMENT, RARCH_GL_RENDERBUFFER,gl->hw_render_depth[i]); } } status=glCheckFramebufferStatus(RARCH_GL_FRAMEBUFFER); if(status!=RARCH_GL_FRAMEBUFFER_COMPLETE) { RARCH_ERR("[GL]:FailedtocreateHWrenderFBO#%u,error:0x%u.\n", i,(unsigned)status); returnfalse; } } gl_bind_backbuffer(); gl->hw_render_fbo_init=true; context_bind_hw_render(false); returntrue; }Example#80ShowfileFile: FrameBufferObject.cpp Project: slicedpan/GLUtilsFrameBufferObject::FrameBufferObject(intwidth,intheight,intdepthBufferBitDepth,intstencilBufferBitDepth,GLenumtextureFormat,GLenumtextureType,std::stringname) :width(width), height(height), textureFormat(textureFormat), textureType(textureType), texNum(0), nextIndex(0), Height(height), Width(width), Bound(bound) { if(!glGenFramebuffers) throw; bound=false; setDrawBuffers=false; if(name=="") { charbuf[64]; sprintf(buf,"unnamed%d",++nextIndex); this->name=buf; } else { this->name=name; } glGenFramebuffers(1,&glID); glBindFramebuffer(GL_FRAMEBUFFER,glID); if(depthBufferBitDepth||stencilBufferBitDepth) { GLenumformat=0; if(depthBufferBitDepth&&stencilBufferBitDepth) { if(depthBufferBitDepth==32&&stencilBufferBitDepth==8) format=GL_DEPTH32F_STENCIL8; else format=GL_DEPTH24_STENCIL8; GLuintid; glGenRenderbuffers(1,&id); renderBuffers.push_back(id); glBindRenderbuffer(GL_RENDERBUFFER,id); glRenderbufferStorage(GL_RENDERBUFFER,format,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,id); } elseif(stencilBufferBitDepth==0) { if(depthBufferBitDepth==16) format=GL_DEPTH_COMPONENT16; elseif(depthBufferBitDepth==24) format=GL_DEPTH_COMPONENT24; else format=GL_DEPTH_COMPONENT32F; GLuintid; glGenRenderbuffers(1,&id); renderBuffers.push_back(id); glBindRenderbuffer(GL_RENDERBUFFER,id); glRenderbufferStorage(GL_RENDERBUFFER,format,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,id); } } glBindFramebuffer(GL_FRAMEBUFFER,0); }Example#90ShowfileFile: platform_gl.cpp Project: enterstudio/tangram-esvoidGL::renderbufferStorage(GLenumtarget,GLenuminternalformat,GLsizeiwidth, GLsizeiheight){ GL_CHECK(glRenderbufferStorage(target,internalformat,width,height)); }Example#100ShowfileFile: read-after-clear.c Project: BNieuwenhuizen/piglitvoid piglit_init(intargc,char**argv) { GLuintvs,fs_paint_red,fs_sample; GLenumfb_status; /*Parseparams*/ if(argc!=3) print_usage_and_exit(argv[0]); if(strcmp(argv[1],"sample")==0) subtest=SUBTEST_SAMPLE; elseif(strcmp(argv[1],"read_pixels")==0) subtest=SUBTEST_READ_PIXELS; elseif(strcmp(argv[1],"blit")==0) subtest=SUBTEST_BLIT; elseif(strcmp(argv[1],"copy")==0) subtest=SUBTEST_COPY; else print_usage_and_exit(argv[0]); if(strcmp(argv[2],"rb")==0) use_texture=false; elseif(strcmp(argv[2],"tex")==0) use_texture=true; else print_usage_and_exit(argv[0]); /*Detectparameterconflicts*/ if(subtest==SUBTEST_SAMPLE&&!use_texture){ printf("Subtest'sample'requiresbuffer_type'tex'.\n"); piglit_report_result(PIGLIT_FAIL); } /*Requirements*/ piglit_require_gl_version(11); piglit_require_GLSL_version(110); piglit_require_extension("GL_ARB_framebuffer_object"); /*Compileshaders*/ vs=piglit_compile_shader_text(GL_VERTEX_SHADER,vs_text); fs_paint_red=piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text_paint_red); prog_paint_red=piglit_link_simple_program(vs,fs_paint_red); if(!prog_paint_red) piglit_report_result(PIGLIT_FAIL); fs_sample=piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text_sample); prog_sample=piglit_link_simple_program(vs,fs_sample); if(!prog_sample) piglit_report_result(PIGLIT_FAIL); if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /*Setupframebuffer*/ glGenFramebuffers(1,&fb); glBindFramebuffer(GL_FRAMEBUFFER,fb); if(use_texture){ tex1=allocate_texture(); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,tex1,0/*level*/); }else{ GLuintrb; glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, TEX_WIDTH,TEX_HEIGHT); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb); } if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); fb_status=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fb_status!=GL_FRAMEBUFFER_COMPLETE){ printf("Framebufferstatus:%s\n", piglit_get_gl_enum_name(fb_status)); piglit_report_result(PIGLIT_FAIL); } /*Setupsecondtexture(usedby"copy"testonly)*/ if(subtest==SUBTEST_COPY) tex2=allocate_texture(); if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); }Example#110ShowfileFile: learngl.cpp Project: Reshurum/learnglintmain(){ //InitializeGLFWandsetsomehintsthatwillcreateanOpenGL3.3context //usingcoreprofile. glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3); glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); //Createafixed800x600windowthatisnotresizable. GLFWwindow*window=glfwCreateWindow(kWindowWidth,kWindowHeight,"LearnGL",nullptr,nullptr); if(window==nullptr){ std::cerr<limitTime){ fovTime=limitTime; } //Updatetheperspectivetoaccountforchangesinfov. camera.fov=easeOutQuart(fovTime,startFov,(startFov-targetFov)*-1,limitTime); camera.update(); //BindtheVAOandshader. glBindVertexArray(VAO); shader.use(); //Passtheviewandprojectionmatricesfromthecamera. GLuintviewMatrix=glGetUniformLocation(shader.program,"view"); glUniformMatrix4fv(viewMatrix,1,GL_FALSE,glm::value_ptr(camera.view)); GLuintprojectionMatrix=glGetUniformLocation(shader.program,"projection"); glUniformMatrix4fv(projectionMatrix,1,GL_FALSE,glm::value_ptr(camera.projection)); //Generatelightcolors. glm::vec3lightColor(1.0f,1.0f,1.0f); //Directionallight glUniform3f(glGetUniformLocation(shader.program,"dirLight.direction"),-0.2f,-1.0f,-0.3f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.diffuse"),0.4f,0.4f,0.4f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.specular"),0.5f,0.5f,0.5f); //Pointlight1 glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].position"),pointLightPositions[0].x,pointLightPositions[0].y,pointLightPositions[0].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].diffuse"),1.0f,0.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].quadratic"),0.032); //Pointlight2 glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].position"),pointLightPositions[1].x,pointLightPositions[1].y,pointLightPositions[1].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].diffuse"),0.0f,1.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].quadratic"),0.032); //Pointlight3 glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].position"),pointLightPositions[2].x,pointLightPositions[2].y,pointLightPositions[2].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].diffuse"),0.0f,0.0f,1.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].quadratic"),0.032); //Pointlight4 glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].position"),pointLightPositions[3].x,pointLightPositions[3].y,pointLightPositions[3].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].diffuse"),0.8f,0.8f,0.8f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].quadratic"),0.032); //Sportlight1 glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].position"),camera.position.x,camera.position.y,camera.position.z); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].direction"),camera.front.x,camera.front.y,camera.front.z); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].ambient"),0.0f,0.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].diffuse"),1.0f,1.0f,1.0f); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].quadratic"),0.032); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].cutoff"),glm::cos(glm::radians(12.5f))); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].outerCutoff"),glm::cos(glm::radians(15.5f))); //Passmaterialvalues. GLuintmaterialShininess=glGetUniformLocation(shader.program,"material.shininess"); GLuintmaterialDiffuse=glGetUniformLocation(shader.program,"material.diffuse"); GLuintmaterialSpecular=glGetUniformLocation(shader.program,"material.specular"); GLuintmaterialEmission=glGetUniformLocation(shader.program,"material.emission"); glUniform1f(materialShininess,64.0f); glUniform1i(materialDiffuse,0); glUniform1i(materialSpecular,1); glUniform1i(materialEmission,2); //Miscvalues. GLuintviewPos=glGetUniformLocation(shader.program,"viewPos"); glUniform3f(viewPos,camera.position.x,camera.position.y,camera.position.z); GLuinttime=glGetUniformLocation(shader.program,"time"); glUniform1f(time,glfwGetTime()); //Bindthetextures. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,containerTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,containerSpecular); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D,containerEmission); //Drawmultiplecontainers! GLuintmodelMatrix=glGetUniformLocation(shader.program,"model"); GLuintnormalMatrix=glGetUniformLocation(shader.program,"normalMatrix"); for(GLuinti=0;i<10;i++){ //Applyworldtransformations. model=glm::mat4(); model=glm::translate(model,cubePositions[i]); model=glm::rotate(model,i*20.0f,glm::vec3(1.0f,0.3f,0.5f)); glUniformMatrix4fv(modelMatrix,1,GL_FALSE,glm::value_ptr(model)); //CalculatethenormalmatrixontheCPU(keepthemnormalsperpendicular). normal=glm::mat3(glm::transpose(glm::inverse(model))); glUniformMatrix3fv(normalMatrix,1,GL_FALSE,glm::value_ptr(normal)); //Drawthecontainer. glDrawArrays(GL_TRIANGLES,0,36); } glBindVertexArray(0); //BindtheVAOandshader. glBindVertexArray(lightVAO); lampShader.use(); //Passtheviewandprojectionmatricesfromthecamera. viewMatrix=glGetUniformLocation(lampShader.program,"view"); glUniformMatrix4fv(viewMatrix,1,GL_FALSE,glm::value_ptr(camera.view)); projectionMatrix=glGetUniformLocation(lampShader.program,"projection"); glUniformMatrix4fv(projectionMatrix,1,GL_FALSE,glm::value_ptr(camera.projection)); for(GLuinti=0;i<4;i++){ //Applyworldtransformations. model=glm::mat4(); model=glm::translate(model,pointLightPositions[i]); model=glm::scale(model,glm::vec3(0.2f)); modelMatrix=glGetUniformLocation(lampShader.program,"model"); glUniformMatrix4fv(modelMatrix,1,GL_FALSE,glm::value_ptr(model)); //Drawthelamp. glDrawArrays(GL_TRIANGLES,0,36); } glBindVertexArray(0); //Drawsomethingwiththegeometryshaderprogram. //glDisable(GL_DEPTH_TEST); //gsShader.use(); //glBindVertexArray(pointsVAO); //glDrawArrays(GL_POINTS,0,4); //glBindVertexArray(0); //glEnable(GL_DEPTH_TEST); //Unbindtheoffscreenframebuffercontainingtheunprocessedframe. glBindFramebuffer(GL_FRAMEBUFFER,0); glClearColor(1.0f,1.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); postShader.use(); glBindVertexArray(frameVAO); //Sendthetexturesamplertotheshader. GLuintframeTexture=glGetUniformLocation(postShader.program,"frameTexture"); time=glGetUniformLocation(postShader.program,"time"); glUniform1i(frameTexture,0); glUniform1f(time,glfwGetTime()); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,frameColorBuffer); //Renderthecolorbufferintheframebuffertothequadwithpostshader. glDrawArrays(GL_TRIANGLES,0,6); glBindVertexArray(0); //Swapbuffersusedfordoublebuffering. glfwSwapBuffers(window); } //Destroytheoffscreenframebuffer. glBindFramebuffer(GL_FRAMEBUFFER,0); glDeleteFramebuffers(1,&FBO); //ProperlydeallocatetheVBOandVAO. glDeleteVertexArrays(1,&VAO); glDeleteBuffers(1,&VBO); //TerminateGLFWandcleananyresourcesbeforeexiting. glfwTerminate(); return0; }Example#120ShowfileFile: FrameBufferDemo.cpp Project: DarriusWrightGD/GraphicsProgrammingvoidFrameBufferDemo::Initialize() { fboProgram.AddShaderFile(ShaderType::Vertex,"Assets/Shaders/Vertex/fbo.vert"); fboProgram.AddShaderFile(ShaderType::Fragment,"Assets/Shaders/Fragment/fbo.frag"); fboProgram.Build(); textureProgram.AddShaderFile(ShaderType::Vertex,"Assets/Shaders/Vertex/texture.vert"); textureProgram.AddShaderFile(ShaderType::Fragment,"Assets/Shaders/Fragment/texture.frag"); textureProgram.Build(); textureProgram.AddUniformBlock({"TransformBlock",{ {"TransformBlock.view",&camera->GetView()[0][0],sizeof(camera->GetView())}, {"TransformBlock.projection",&camera->GetProjection()[0][0],sizeof(camera->GetProjection())}, }}); fboProgram.AddUniformBlock({"TransformBlock",{ {"TransformBlock.view",&camera->GetView()[0][0],sizeof(camera->GetView())}, {"TransformBlock.projection",&camera->GetProjection()[0][0],sizeof(camera->GetProjection())}, }}); input->addBinding(GLFW_KEY_LEFT,[this](InputInfoinfo){ camera->MoveLeft(); fboProgram.UpdateUniformBlock("TransformBlock"); textureProgram.UpdateUniformBlock("TransformBlock"); }); input->addBinding(GLFW_KEY_RIGHT,[this](InputInfoinfo){ camera->MoveRight(); fboProgram.UpdateUniformBlock("TransformBlock"); textureProgram.UpdateUniformBlock("TransformBlock"); }); input->addBinding(GLFW_KEY_UP,[this](InputInfoinfo){ camera->MoveForward(); textureProgram.UpdateUniformBlock("TransformBlock"); fboProgram.UpdateUniformBlock("TransformBlock"); }); input->addBinding(GLFW_KEY_DOWN,[this](InputInfoinfo){ camera->MoveBack(); textureProgram.UpdateUniformBlock("TransformBlock"); fboProgram.UpdateUniformBlock("TransformBlock"); }); glGenFramebuffers(1,&fboHandle); glBindFramebuffer(GL_FRAMEBUFFER,fboHandle); glGenTextures(1,&renderTargetTexture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,renderTargetTexture); glTexStorage2D(GL_TEXTURE_2D,1,GL_RGBA8,512,512); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,renderTargetTexture,0); glGenRenderbuffers(1,&depthBufferTexture); glBindRenderbuffer(GL_RENDERBUFFER,depthBufferTexture); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,512,512); GLenumdrawBufs[]={GL_COLOR_ATTACHMENT0}; glDrawBuffers(1,drawBufs); glBindFramebuffer(GL_FRAMEBUFFER,0); Assimp::Importerimporter; autocubeScene=importer.ReadFile("Assets/Models/Obj/box.obj",aiProcess_Triangulate); cube=std::unique_ptr(newGameObject()); cube->GetTransform()->SetPosition({0.0f,0.0f,-5.0f}); cube->GetTransform()->SetScale({20.0f,20.0f,20.0f}); cube->Update(); if(cubeScene&&cubeScene->HasMeshes()) { cubeMesh=std::unique_ptr(newMeshComponent(cube.get())); cubeMesh->Initialize(cubeScene->mMeshes[0],fboProgram,{ {"world",UniformType::MAT4,&cube->GetWorld()[0][0]}, }); cubeMesh->AddTexture({renderTargetTexture,GL_TEXTURE_2D,renderer->GetSampler(SamplerType::Linear).sampler}); } automonkeyScene=importer.ReadFile("Assets/Models/Obj/monkey.obj",aiProcess_Triangulate); monkey=std::unique_ptr(newGameObject()); monkey->GetTransform()->SetPosition({2.0f,0.0f,-2.0f}); monkey->Update(); if(monkeyScene&&monkeyScene->HasMeshes()) { monkeyMesh=std::unique_ptr(newMeshComponent(monkey.get())); monkeyMesh->Initialize(monkeyScene->mMeshes[0],textureProgram,{ {"world",UniformType::MAT4,&monkey->GetWorld()[0][0]} }); monkeyMesh->AddTexture("Assets/Textures/brick.jpg"); } importer.FreeScene(); }Example#130ShowfileFile: webgl.cpp Project: cebu4u/TrickplayboolContext::try_create_fbo(GLsizeiwidth,GLsizeiheight,intflags) { tplog2("CREATINGFRAMEBUFFER"); GLuint fbo; GLuintSet rb; boolh_depth=false; boolh_stencil=false; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,texture_target,texture,0); if(flags&FBO_TRY_DEPTH_STENCIL) { tplog2("CREATINGDEPTH/STENCILRENDERBUFFERS"); GLuintdepth_stencil_rb; glGenRenderbuffers(1,&depth_stencil_rb); glBindRenderbuffer(GL_RENDERBUFFER,depth_stencil_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_STENCIL,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,depth_stencil_rb); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth_stencil_rb); rb.insert(depth_stencil_rb); h_depth=true; h_stencil=true; } if(flags&FBO_TRY_DEPTH) { tplog2("CREATINGDEPTHRENDERBUFFER"); GLuintdepth_rb; glGenRenderbuffers(1,&depth_rb); glBindRenderbuffer(GL_RENDERBUFFER,depth_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth_rb); rb.insert(depth_rb); h_depth=true; } if(flags&FBO_TRY_STENCIL) { tplog2("CREATINGSTENCILRENDERBUFFER"); GLuintstencil_rb; glGenRenderbuffers(1,&stencil_rb); glBindRenderbuffer(GL_RENDERBUFFER,stencil_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_STENCIL_INDEX8,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,stencil_rb); rb.insert(stencil_rb); h_stencil=true; } if(GL_FRAMEBUFFER_COMPLETE!=glCheckFramebufferStatus(GL_FRAMEBUFFER)) { glBindFramebuffer(GL_FRAMEBUFFER,0); tplog2("DESTROYINGFRAMEBUFFER%u",fbo); glDeleteFramebuffers(1,&fbo); for(GLuintSet::const_iteratorit=rb.begin();it!=rb.end();++it) { tplog2("DESTROYINGRENDERBUFFER%u",*it); glDeleteRenderbuffers(1,&*it); } tplog2("*FRAMEBUFFERISNOTCOMPLETE"); returnfalse; } tplog2("*FRAMEBUFFERISCOMPLETE"); framebuffer=fbo; renderbuffers.insert(rb.begin(),rb.end()); have_depth=h_depth; have_stencil=h_stencil; returntrue; }Example#140ShowfileFile: fbo.cpp Project: wdings23/gl-projectsvoidfboInit(tFBOInfo*pFBOInfo,intiWidth,intiHeight,intiTextureFilter) { //bindfbototexture glGenFramebuffers(1,&pFBOInfo->mFBO); glBindFramebuffer(GL_FRAMEBUFFER,pFBOInfo->mFBO); //colorbufferforfbo glGenRenderbuffers(1,&pFBOInfo->mColorRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,pFBOInfo->mColorRenderBuffer); #ifdefined(WIN32)||defined(MACOS) glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB8,iWidth,iHeight); #else glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB8_OES,iWidth,iHeight); #endif//WIN32 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,pFBOInfo->mColorRenderBuffer); //depthbufferforthefbo glGenRenderbuffers(1,&pFBOInfo->mDepthRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,pFBOInfo->mDepthRenderBuffer); #ifdefined(WIN32)||defined(MACOS) glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24,iWidth,iHeight); #else glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24_OES,iWidth,iHeight); #endif//WIN32 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,pFBOInfo->mDepthRenderBuffer); //texture glGenTextures(1,&pFBOInfo->mTexture); glBindTexture(GL_TEXTURE_2D,pFBOInfo->mTexture); GLuintiGLFilterType=GL_NEAREST; if(iTextureFilter==FILTER_BILINEAR) { iGLFilterType=GL_LINEAR; } elseif(iTextureFilter==FILTER_NEAREST) { iGLFilterType=GL_NEAREST; } //attribute glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,iGLFilterType); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,iGLFilterType); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iWidth, iHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pFBOInfo->mTexture, 0); glBindFramebuffer(GL_FRAMEBUFFER,0); }Example#150ShowfileFile: gBuffer.cpp Project: kosakasakas/of-DeferredRenderingboolGBuffer::setupFbo(unsignedintwindowWidth,unsignedintwindowHeight){ m_buffer_w=windowWidth; m_buffer_h=windowHeight; //deleteexistingfbo,textures,andrenderbufferincaseweareregeneratingatnewsize glDeleteTextures(GBUFFER_NUM_TEXTURES,m_textures); glDeleteRenderbuffers(1,&m_renderBuffer); glDeleteFramebuffers(1,&m_fbo); //createanfbo glGenFramebuffers(1,&m_fbo); glBindFramebuffer(GL_FRAMEBUFFER,m_fbo); //createallgbuffertextures glGenTextures(GBUFFER_NUM_TEXTURES,m_textures); //albedo/diffuse(16-bitchannelrgba) glBindTexture(GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_ALBEDO]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F,m_buffer_w,m_buffer_h,0,GL_RGBA,GL_FLOAT,NULL); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+GBUFFER_TEXTURE_TYPE_ALBEDO,GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_ALBEDO],0); //normals+depth(32-bitRGBAfloatforaccuracy) glBindTexture(GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA32F,m_buffer_w,m_buffer_h,0,GL_RGBA,GL_FLOAT,NULL); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH,GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH],0); //lightingpass(16-bitRGBA) glBindTexture(GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_LIGHT_PASS]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,m_buffer_w,m_buffer_h,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+GBUFFER_TEXTURE_TYPE_LIGHT_PASS,GL_TEXTURE_2D,m_textures[GBUFFER_TEXTURE_TYPE_LIGHT_PASS],0); //createdepthtexture(wedon'tusethisexplicitly,butsinceweusedepthtestingwhenrendering+forourstencilpass,ourFBOneedsadepthbuffer) //wemakeitarenderbufferandnotatextureaswe'llneveraccessitdirectlyinashader glGenRenderbuffers(1,&m_renderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,m_renderBuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH32F_STENCIL8,m_buffer_w,m_buffer_h); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,m_renderBuffer); //checkstatus GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER,0); glBindRenderbuffer(GL_RENDERBUFFER,0); glBindTexture(GL_TEXTURE_2D,0); if(status!=GL_FRAMEBUFFER_COMPLETE){ ofLogError("GBuffer::setupFbo()","Couldnotcreateframebuffer"); returnfalse; } returntrue; }Example#160ShowfileFile: main.cpp Project: Johnm95/GP2CourseWorkvoidcreateFramebuffer() { glActiveTexture(GL_TEXTURE0); glGenTextures(1,&FBOTexture); glBindTexture(GL_TEXTURE_2D,FBOTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,FRAME_BUFFER_WIDTH,FRAME_BUFFER_HEIGHT,0,GL_RGBA, GL_UNSIGNED_BYTE,NULL); glGenRenderbuffers(1,&FBODepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER,FBODepthBuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT32,FRAME_BUFFER_WIDTH,FRAME_BUFFER_HEIGHT); glBindRenderbuffer(GL_RENDERBUFFER,0); glGenFramebuffers(1,&frameBufferObject); glBindFramebuffer(GL_FRAMEBUFFER,frameBufferObject); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,FBOTexture,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,FBODepthBuffer); GLenumstatus; if((status=glCheckFramebufferStatus(GL_FRAMEBUFFER))!=GL_FRAMEBUFFER_COMPLETE){ cout<newtextures,std::ostream&error_output,boolforce_multisample_off) { OPENGL_UTILITY::CheckForOpenGLErrors("FBOinitstart",error_output); constboolverbose=false; if(inited) { if(verbose)error_output<color_textures; std::vectordepth_textures; for(std::vector::iteratori=textures.begin();i!=textures.end();i++) { if((*i)->texture_format==FBTEXTURE::DEPTH24) depth_textures.push_back(*i); else color_textures.push_back(*i); //assert(!(*i)->attached||(force_multisample_off&&(*i)->renderbuffer_multisample!=0)); (*i)->attached=true; } if(verbose)error_output<=1); //can'thavemorethanonedepthattachment assert(depth_textures.size()<2); //can'thavemorethan4colortextures assert(color_textures.size()<5); for(std::vector::iteratori=color_textures.begin();i!=color_textures.end();i++) { if((*i)->texture_target==FBTEXTURE::CUBEMAP) { if(verbose)error_output<multisample==0); //can'thavedepthtexturewithcubemaps assert(depth_textures.empty()); } } //findwhatmultisamplevaluetouse intmultisample=0; if(!color_textures.empty()) { multisample=-1; for(std::vector::iteratori=textures.begin();i!=textures.end();i++) { if(multisample==-1) multisample=(*i)->multisample; //allmusthavethesamemultisample assert(multisample==(*i)->multisample); } } if(verbose)error_output<0)&&depth_textures.empty())); //ensureconsistentsizes width=-1; height=-1; for(std::vector::iteratori=textures.begin();i!=textures.end();i++) { if(width==-1) width=(*i)->sizew; if(height==-1) height=(*i)->sizeh; assert(width==(*i)->sizew); assert(height==(*i)->sizeh); } if(verbose)error_output<0) { //needaseparatemultisampledepthbuffer glRenderbufferStorageMultisample(GL_RENDERBUFFER,multisample,GL_DEPTH_COMPONENT,width,height); if(verbose)error_output<::iteratori=color_textures.begin();i!=color_textures.end();i++,count++) { buffers[count]=GL_COLOR_ATTACHMENT0+count; } } glDrawBuffers(4,buffers); glReadBuffer(buffers[0]); if(verbose)error_output<0) { intcount=0; for(std::vector::iteratori=color_textures.begin();i!=color_textures.end();i++,count++) { //needaseparatemultisamplecolorbuffer glGenRenderbuffers(1,&(*i)->renderbuffer_multisample); glBindRenderbuffer(GL_RENDERBUFFER,(*i)->renderbuffer_multisample); glRenderbufferStorageMultisample(GL_RENDERBUFFER,multisample,(*i)->texture_format,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+count,GL_RENDERBUFFER,(*i)->renderbuffer_multisample); if(verbose)error_output<::iteratori=color_textures.begin();i!=color_textures.end();i++,count++) { inttexture_attachment=GL_COLOR_ATTACHMENT0+count; if(multisample==0) { if((*i)->texture_target==FBTEXTURE::CUBEMAP) { //ifwe'reusingacubemap,arbitrarilypickoneofthefacestoactivatesowecancheckthattheFBOiscomplete glFramebufferTexture2D(GL_FRAMEBUFFER,texture_attachment,GL_TEXTURE_CUBE_MAP_POSITIVE_X,(*i)->fbtexture,0); if(verbose)error_output<texture_target,(*i)->fbtexture,0); if(verbose)error_output<texture_attachment=texture_attachment; } } } //attachthedepthtexturetotheFBO,ifthereisone { intcount=0; for(std::vector::iteratori=depth_textures.begin();i!=depth_textures.end();i++,count++) { if(multisample==0) { if((*i)->texture_target==FBTEXTURE::CUBEMAP) { //ifwe'reusingacubemap,arbitrarilypickoneofthefacestoactivatesowecancheckthattheFBOiscomplete glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_CUBE_MAP_POSITIVE_X,(*i)->fbtexture,0); if(verbose)error_output<texture_target,(*i)->fbtexture,0); if(verbose)error_output<::iteratori=textures.begin();i!=textures.end();i++) { error_output<texture_target)<texture_format)<<:endl count assert glstate.bindframebuffer opengl_utility::checkforopenglerrors if>0) { if(verbose)error_output<lightPositions; lightPositions.push_back(glm::vec3(0.0f,0.0f,49.5f));//backlight lightPositions.push_back(glm::vec3(-1.4f,-1.9f,9.0f)); lightPositions.push_back(glm::vec3(0.0f,-1.8f,4.0f)); lightPositions.push_back(glm::vec3(0.8f,-1.7f,6.0f)); //colors std::vector<:vec3>lightColors; lightColors.push_back(glm::vec3(200.0f,200.0f,200.0f)); lightColors.push_back(glm::vec3(0.1f,0.0f,0.0f)); lightColors.push_back(glm::vec3(0.0f,0.0f,0.2f)); lightColors.push_back(glm::vec3(0.0f,0.1f,0.0f)); //shaderconfiguration //-------------------- shader.use(); shader.setInt("diffuseTexture",0); hdrShader.use(); hdrShader.setInt("hdrBuffer",0); //renderloop //----------- while(!glfwWindowShouldClose(window)) { //per-frametimelogic //-------------------- floatcurrentFrame=glfwGetTime(); deltaTime=currentFrame-lastFrame; lastFrame=currentFrame; //input //----- processInput(window); //render //------ glClearColor(0.1f,0.1f,0.1f,1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //1.rendersceneintofloatingpointframebuffer //----------------------------------------------- glBindFramebuffer(GL_FRAMEBUFFER,hdrFBO); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glm::mat4projection=glm::perspective(camera.Zoom,(GLfloat)SCR_WIDTH/(GLfloat)SCR_HEIGHT,0.1f,100.0f); glm::mat4view=camera.GetViewMatrix(); shader.use(); shader.setMat4("projection",projection); shader.setMat4("view",view); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,woodTexture); //setlightinguniforms for(unsignedinti=0;iinternal_format, TEX_SIZE,TEX_SIZE,1,samples, src_format->format, src_format->data_type,src_data); dst_tex=piglit_multisample_texture(GL_TEXTURE_2D_MULTISAMPLE,0, dst_format->internal_format, TEX_SIZE,TEX_SIZE,1,samples, dst_format->format, dst_format->data_type,dst_data); res_tex=piglit_multisample_texture(GL_TEXTURE_2D_MULTISAMPLE,0, dst_format->internal_format, TEX_SIZE,TEX_SIZE,1,samples, dst_format->format, dst_format->data_type,res_data); pass&=piglit_check_gl_error(GL_NO_ERROR); /*Ifanyofthesearezero,buttherewasnoerror,thenitmust *notberenderable,sowejustskipwithoutevenreportingthe *subtest. */ if((src_tex==0||dst_tex==0||res_tex==0)&&pass) returnPIGLIT_SKIP; glCopyImageSubData(src_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/4,TEX_SIZE/4,0, dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/4,TEX_SIZE/4,0, TEX_SIZE/2,TEX_SIZE/2,1); pass&=piglit_check_gl_error(GL_NO_ERROR); glCopyImageSubData(dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, 0,TEX_SIZE/2,0, dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/2,0,0, TEX_SIZE/2,TEX_SIZE/2,1); pass&=piglit_check_gl_error(GL_NO_ERROR); if(piglit_automatic){ fbo_width=TEX_SIZE; fbo_height=TEX_SIZE; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, fbo_width,fbo_height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb); }else{ fbo_width=piglit_width; fbo_height=piglit_height; glBindFramebuffer(GL_FRAMEBUFFER,piglit_winsys_fbo); } pass&=piglit_check_gl_error(GL_NO_ERROR); glViewport(0,0,fbo_width,fbo_height); glClearColor(1.0f,0.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); /*Nowweuseacomparisonshadertochecktoseeifthe *destinationmatchestheexpectedresult. */ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,dst_tex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,res_tex); load_compare_program(dst_format); pass&=piglit_check_gl_error(GL_NO_ERROR); glEnableVertexAttribArray(0); glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,verts); glDrawArrays(GL_TRIANGLES,0,6); glDisableVertexAttribArray(0); pass&=piglit_check_gl_error(GL_NO_ERROR); /*Ifthedestinationtexturematchestheexpectedresult,we *shouldgetgreen.Ifnot,wegetredandthistestfails. */ pass&=piglit_probe_rect_rgb(0,0,fbo_width,fbo_height,green); glDeleteTextures(1,&src_tex); glDeleteTextures(1,&dst_tex); glDeleteTextures(1,&res_tex); if(!piglit_automatic) piglit_present_results(); returnpass?PIGLIT_PASS:PIGLIT_FAIL; }Example#220ShowfileFile: renderer.hpp Project: BJLinc/df-twbtvoidrenderer_cool::draw(intvertex_count) { staticboolinitial_resize=false; if(!initial_resize) { if(enabler->fullscreen) resize(size_x,size_y); else resize((size_x/init->font.small_font_dispx)*init->font.small_font_dispx,(size_y/init->font.small_font_dispy)*init->font.small_font_dispy); //resize(gps->dimx*init->font.small_font_dispx,gps->dimy*init->font.small_font_dispy); reshape_gl(); initial_resize=true; } staticdf::viewscreen*prevws=NULL; df::viewscreen*ws=Gui::getCurViewscreen(); is_main_scr=df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws)||df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws); if(ws!=prevws) { gps->force_full_display_count=1; prevws=ws; /*if(is_main_scr) { for(intx=1;xdimx-gmenu_w-1;x++) { for(inty=1;ydimy-1;y++) { constinttile1=x*gps->dimy+y; for(inti=0;i<6;i++) *(fg+tile*4*i+3)=0; } } }*/ } display_new(is_main_scr); #ifdefWIN32 //Wecan'tdothisinplugin_init()becauseOpenGLcontextisn'tinitializedbythattime staticboolglew_init=false; if(!glew_init) { GLenumerr=glewInit(); if(err!=GLEW_OK) *out2<dimx; old_dimy=gps->dimy; old_winx=*df::global::window_x; old_winy=*df::global::window_y; grid_resize(world->map.x_count+36,world->map.y_count+2); *df::global::window_x=0; *df::global::window_y=0; gps->force_full_display_count=1; } domapshot--; } GLuintframebuffer,renderbuffer; GLenumstatus; if(domapshot==5) { //Setthewidthandheightappropriatelyforyourimage GLuintimageWidth=gps->dimx*dispx, imageHeight=gps->dimy*dispy; //SetupaFBOwithonerenderbufferattachment glGenFramebuffers(1,&framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); glGenRenderbuffers(1,&renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,renderbuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8,imageWidth,imageHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,renderbuffer); glViewport(0,0,gps->dimx*dispx,gps->dimy*dispy); /*glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,gps->dimx,gps->dimy,0,-1,1);*/ } if(is_main_scr) { boolskip=false; if(df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws)) { intm=df::global::ui_advmode->menu; booltmode=advmode_needs_map(m); skip=!tmode; } if(!skip) { ///// glViewport(goff_x,goff_y_gl,gdimx*gdispx,gdimy*gdispy); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,gdimx,gdimy,0,-1,1); //glTranslatef(1,-1,0); //glScissor(off_x+(float)size_x/gps->dimx,off_y+(float)size_y/gps->dimy,gsize_x,gsize_y); //glEnable(GL_SCISSOR_TEST); //glClearColor(1,0,0,1); //glClear(GL_COLOR_BUFFER_BIT); if(multi_rendered&&fogdensity>0) { glEnable(GL_FOG); glFogfv(GL_FOG_COLOR,fogcolor); glFogf(GL_FOG_DENSITY,fogdensity); glFogi(GL_FOG_COORD_SRC,GL_FOG_COORD); glEnableClientState(GL_FOG_COORD_ARRAY); glFogCoordPointer(GL_FLOAT,0,fogcoord); } glVertexPointer(2,GL_FLOAT,0,gvertexes); //Renderbackgroundcolors glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_BLEND); glColorPointer(4,GL_FLOAT,0,gbg); glDrawArrays(GL_TRIANGLES,0,gdimx*gdimy*6); //Renderforeground glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTexCoordPointer(2,GL_FLOAT,0,gtex); glColorPointer(4,GL_FLOAT,0,gfg); glDrawArrays(GL_TRIANGLES,0,gdimx*gdimy*6); if(multi_rendered) { glDisableClientState(GL_FOG_COORD_ARRAY); glDisable(GL_FOG); } //Prepareandrendershadows if(multi_rendered) { intelemcnt=0; //TODO:don'tdothisifviewnotmovedandtileswithshadowsnotchanged { gl_texpos*txt=(gl_texpos*)enabler->textures.gl_texpos; intx1=std::min(gdimx,world->map.x_count-gwindow_x); inty1=std::min(gdimy,world->map.y_count-gwindow_y); for(inttile=0;tile0&&(depth[((xx-1)*gdimy+yy)])0&&(depth[((xx)*gdimy+yy-1)])0&&yy0&&yy>0&&(depth[((xx-1)*gdimy+yy-1)])0&&(depth[((xx+1)*gdimy+yy-1)])map.x_count*dispx; inth=world->map.y_count*dispy; unsignedchar*data=(unsignedchar*)malloc(w*h*3); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_PACK_ROW_LENGTH,0); glReadPixels(dispx,dispy,w,h,GL_BGR,GL_UNSIGNED_BYTE,data); #pragmapack(push,1) typedefstruct_TgaHeader { unsignedcharIDLength;/*00hSizeofImageIDfield*/ unsignedcharColorMapType;/*01hColormaptype*/ unsignedcharImageType;/*02hImagetypecode*/ unsignedshortCMapStart;/*03hColormaporigin*/ unsignedshortCMapLength;/*05hColormaplength*/ unsignedcharCMapDepth;/*07hDepthofcolormapentries*/ unsignedshortXOffset;/*08hXoriginofimage*/ unsignedshortYOffset;/*0AhYoriginofimage*/ unsignedshortWidth;/*0ChWidthofimage*/ unsignedshortHeight;/*0EhHeightofimage*/ unsignedcharPixelDepth;/*10hImagepixelsize*/ unsignedcharImageDescriptor;/*11hImagedescriptorbyte*/ }TGAHEAD; #pragmapop TGAHEADhdr; memset(&hdr,0,sizeof(hdr)); hdr.ImageType=2; hdr.Width=w; hdr.Height=h; hdr.PixelDepth=24; *out2<force_full_display_count=1; domapshot=0; } }Example#230ShowfileFile: test_SSAO.cpp Project: ProkopHapala/SimpleSimulationEnginevoidsetup(){ //-------------object object1=newGLObject(); object1->draw_mode=GL_TRIANGLE_STRIP; object1->nVert=4; object1->buffs[0].setup(0,2,GL_FALSE,&vertexes[0][0],'v');//vertexes object1->init(); //-------------shaderforrenderinggeometry shader_pre=newShader(); //shader_pre->init("shaders/afine2D_vert.c","shaders/sphere_frag.c"); shader_pre->init("shaders/afine2D_vert.c","shaders/sphereHoled_frag.c"); //randf(-1.0,1.0); for(inti=0;ishaderprogram); GLuintuloc; uloc=glGetUniformLocation(shader_pre->shaderprogram,"resolution"); glUniform2fv(uloc,1,resolution); uloc=glGetUniformLocation(shader_pre->shaderprogram,"camPos"); glUniform3fv(uloc,1,camPos); uloc=glGetUniformLocation(shader_pre->shaderprogram,"camMat"); glUniformMatrix3fv(uloc,1,false,camMat); uloc=glGetUniformLocation(shader_pre->shaderprogram,"sphere"); glUniform4fv(uloc,1,sphere); uloc=glGetUniformLocation(shader_pre->shaderprogram,"light_dir"); glUniform3fv(uloc,1,light_dir); uloc=glGetUniformLocation(shader_pre->shaderprogram,"afineMat"); glUniformMatrix2fv(uloc,1,GL_FALSE,afineMat); uloc=glGetUniformLocation(shader_pre->shaderprogram,"origin"); glUniform2fv(uloc,1,origin); //-------------shaderforblittingfromtexture shader_post=newShader(); shader_post->init("shaders/plain_vert.c","shaders/SSAO_frag.c"); resolution[0]=(float)WIDTH; resolution[1]=(float)HEIGHT; glUseProgram(shader_post->shaderprogram); uloc=glGetUniformLocation(shader_post->shaderprogram,"resolution"); glUniform2fv(uloc,1,resolution); //-------------texture glGenTextures(1,&texRGB); glBindTexture(GL_TEXTURE_2D,texRGB); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,WIDTH,HEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,0); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glGenTextures(1,&texZ); glBindTexture(GL_TEXTURE_2D,texZ); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,WIDTH,HEIGHT,0,GL_DEPTH_COMPONENT,GL_FLOAT,0); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //-------------frameBuffer glGenFramebuffers(1,&FramebufferName); glBindFramebuffer(GL_FRAMEBUFFER,FramebufferName); //Thedepthbuffer glGenRenderbuffers(1,&depthrenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,depthrenderbuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,WIDTH,HEIGHT); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depthrenderbuffer); //Set"renderedTexture"asourcolourattachement#0 glFramebufferTexture(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,texZ,0); glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,texRGB,0); GLenumDrawBuffers[2]={GL_DEPTH_ATTACHMENT,GL_COLOR_ATTACHMENT0}; glDrawBuffers(2,DrawBuffers); /* glFramebufferTexture(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,texZ,0); GLenumDrawBuffers[1]={GL_DEPTH_ATTACHMENT}; glDrawBuffers(1,DrawBuffers); */ if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE){ printf("probleminFBO!\n"); checkFramebufferStatus(); } }Example#240ShowfileFile: SolBufferObjects.cpp Project: gwthomas/sol-frameworkvoidRenderbuffer::storage(unsignedintformat,Vec2isize) { bind(); glRenderbufferStorage(GL_RENDERBUFFER,format,size.x,size.y); }Example#250ShowfileFile: GLObjects.hpp Project: brunodea/cgat2voidsetStorage(GLenuminternalformat,intwidth,intheight) { glRenderbufferStorage(GL_RENDERBUFFER,internalformat,width,height); }Example#260ShowfileFile: CoinRiftWidget.cpp Project: 3DPrinterGuy/FreeCADvoidCoinRiftWidget::initializeGL() { makeCurrent(); //Inferhardwarecapabilites. #ifdefUSE_FRAMEBUFFER OVR::CAPI::GL::InitGLExtensions(); if(OVR::CAPI::GL::glBindFramebuffer==NULL){ qDebug()<(&eyeTexture[eye]); texData->Header.API=ovrRenderAPI_OpenGL; texData->Header.TextureSize=eyeTexture[eye].Header.TextureSize; texData->Header.RenderViewport=eyeTexture[eye].Header.RenderViewport; glGenTextures(1,&texData->TexId); glBindTexture(GL_TEXTURE_2D,texData->TexId); Q_ASSERT(!glGetError()); //Allocatestorageforthetexture. glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,eyeTexture[eye].Header.TextureSize.w,eyeTexture[eye].Header.TextureSize.h,0,GL_BGRA,GL_UNSIGNED_BYTE,NULL); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); Q_ASSERT(!glGetError()); #ifdefUSE_FRAMEBUFFER //Attachtexturetoframebuffercolorobject. OVR::CAPI::GL::glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,texData->TexId,0); if(OVR::CAPI::GL::glCheckFramebufferStatus(GL_FRAMEBUFFER)!= GL_FRAMEBUFFER_COMPLETE) qDebug()<Render(); if(Global::Shadows_enabled==true) ShadowObject::Update(cam); //glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,0); glBindTexture(target,texture);// glGenerateMipmap(target); glBindFramebuffer(GL_FRAMEBUFFER,0); glBindRenderbuffer(GL_RENDERBUFFER,0); }Example#290ShowfileFile: FBO.cpp Project: jonasstrandstedt/infvisGLvoidgl4::FBO::init(GLuintwidth,GLuintheight,GLuintsamples,GLuinttextures){ _textures=textures; _fboTextureId=newGLuint[textures]; GLuint*_rboId=newGLuint[textures]; GLuint_dboId=-1; GLuint*_rboId_multisampled=newGLuint[textures]; GLuint_dboId_multisampled=-1; _w=width; _h=height; GLenumerrorID; GLenumstatus; std::cout<MaxSamples) { samples=MaxSamples; } if(samples>0&&samples<=MaxSamples) { _multisampled=true; std::cout<getWinSizeInPixels(); //_fullviewPort=Rect(0,0,size.width,size.height); w=(int)(w*CC_CONTENT_SCALE_FACTOR()); h=(int)(h*CC_CONTENT_SCALE_FACTOR()); _fullviewPort=Rect(0,0,w,h); glGetIntegerv(GL_FRAMEBUFFER_BINDING,&_oldFBO); //texturesmustbepoweroftwosquared intpowW=0; intpowH=0; if(Configuration::getInstance()->supportsNPOT()) { powW=w; powH=h; } else { powW=ccNextPOT(w); powH=ccNextPOT(h); } autodataLen=powW*powH*4; data=malloc(dataLen); CC_BREAK_IF(!data); memset(data,0,dataLen); _pixelFormat=format; _texture=new(std::nothrow)Texture2D(); if(_texture) { _texture->initWithData(data,dataLen,(Texture2D::PixelFormat)_pixelFormat,powW,powH,Size((float)w,(float)h)); } else { break; } GLintoldRBO; glGetIntegerv(GL_RENDERBUFFER_BINDING,&oldRBO); if(Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { _textureCopy=new(std::nothrow)Texture2D(); if(_textureCopy) { _textureCopy->initWithData(data,dataLen,(Texture2D::PixelFormat)_pixelFormat,powW,powH,Size((float)w,(float)h)); } else { break; } } //generateFBO glGenFramebuffers(1,&_FBO); glBindFramebuffer(GL_FRAMEBUFFER,_FBO); //associatetexturewithFBO glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_texture->getName(),0); if(depthStencilFormat!=0) { //createandattachdepthbuffer glGenRenderbuffers(1,&_depthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER,_depthRenderBufffer); glRenderbufferStorage(GL_RENDERBUFFER,depthStencilFormat,(GLsizei)powW,(GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,_depthRenderBufffer); //ifdepthformatistheonewithstencilpart,bindsamerenderbufferasstencilattachment if(depthStencilFormat==GL_DEPTH24_STENCIL8) { glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,_depthRenderBufffer); } } //checkifitworked(probablyworthdoing:)) CCASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE,"Couldnotattachtexturetoframebuffer"); _texture->setAliasTexParameters(); //retained setSprite(Sprite::createWithTexture(_texture)); _texture->release(); _sprite->setFlippedY(true); _sprite->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,_oldFBO); //Diabledbydefault. _autoDraw=false; //addspriteforbackwardcompatibility addChild(_sprite); ret=true; }while(0); CC_SAFE_FREE(data); returnret; }reportthisadxx



請為這篇文章評分?