C++ (Cpp) glCheckFramebufferStatus Examples - HotExamples

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

C++ (Cpp) glCheckFramebufferStatus - 30 examples found. These are the top rated real world C++ (Cpp) examples of glCheckFramebufferStatus extracted from ... Togglenavigation HotExamplesENENRUDEFRESPTITJPZH C++PHPC#JavaGoC++PythonJSTS SearchC++(Cpp)glCheckFramebufferStatusExamplesC++(Cpp)glCheckFramebufferStatus-30examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglCheckFramebufferStatusextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glCheckFramebufferStatusExamplesathotexamples.com:30reportthisadRelatedCrossThreadPersistentao_shutdownGlobalAllocLOG_WARNINGgameExInitializeFastMutexfegetroundsnd_soc_dai_set_sysclktls_protocol_maskmsg_warnreportthisadRelatedinlangsKeyring_SingleStore(PHP)AbstractEntity(PHP)BlackHole(C#)WeakAction(C#)NewMultiaddrBytes(Go)WriteShort(Go)DocumentBuilder(Java)DbWineCellarDAO(Java)create_folder(Python)debug(Python)reportthisadExample#10ShowfileFile: blit.c Project: Zoxc/piglitbool testFramebufferBlitLayered(intx,inty,boolsrcLayered,booldstLayered) { boolpass=true; GLuintsrcFBO,dstFBO; GLuintsrcTex,dstTex; GLenumfbStatus; /*Setupsourcefbo*/ glGenFramebuffers(1,&srcFBO); glBindFramebuffer(GL_FRAMEBUFFER,srcFBO); piglit_check_gl_error(GL_NO_ERROR); if(srcLayered){ srcTex=create_bind_texture(GL_TEXTURE_3D,true); glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, srcTex,0); }else{ srcTex=create_bind_texture(GL_TEXTURE_2D,true); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,srcTex,0); } /*Checksourceframebufferstatus*/ fbStatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fbStatus!=GL_FRAMEBUFFER_COMPLETE){ printf("testFramebufferBlitLayeredsrcFBOStatus:%s\n", piglit_get_gl_enum_name(fbStatus)); returnfalse; } /*Setupdsttfbo*/ glGenFramebuffers(1,&dstFBO); glBindFramebuffer(GL_FRAMEBUFFER,dstFBO); if(dstLayered){ dstTex=create_bind_texture(GL_TEXTURE_3D,false); glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, dstTex,0); }else{ dstTex=create_bind_texture(GL_TEXTURE_2D,false); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,dstTex,0); } /*Checkdestinationframebufferstatus*/ fbStatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fbStatus!=GL_FRAMEBUFFER_COMPLETE){ printf("testFramebufferBlitLayereddstFBOStatus:%s\n", piglit_get_gl_enum_name(fbStatus)); returnfalse; } /*Checkforifanyerrorshaveoccured*/ if(!piglit_check_gl_error(GL_NO_ERROR)){ printf("Errorsettingupframebuffersfortest.\n"); returnfalse; } /*Blitfromsourcetodestinationframebuffers*/ glBindFramebuffer(GL_READ_FRAMEBUFFER,srcFBO); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,dstFBO); glBlitFramebuffer(0,0,texWidth,texHeight, 0,0,texWidth,texHeight, GL_COLOR_BUFFER_BIT,GL_LINEAR); /*Displaytheresults*/ display_texture(x,y,srcTex,srcLayered?texDepth:1); display_texture(x+texWidth,y,dstTex,dstLayered?texDepth:1); /*Checkforpasscondition*/ if(dstLayered){ pass=piglit_probe_rect_rgb(x+texWidth,y, texWidth,texHeight,srcColors[0])&&pass; pass=piglit_probe_rect_rgb(x+texWidth,y+texHeight, texWidth,texHeight,dstColors[1])&&pass; }else{ pass=piglit_probe_rect_rgb(x+texWidth,y,texWidth, texDepth*texHeight,srcColors[0])&&pass; } /*Cleanup*/ glBindFramebuffer(GL_FRAMEBUFFER,piglit_winsys_fbo); glDeleteFramebuffers(1,&srcFBO); glDeleteFramebuffers(1,&dstFBO); glDeleteTextures(1,&srcTex); glDeleteTextures(1,&dstTex); /*Checkforifanyerrorshaveoccured*/ if(!piglit_check_gl_error(GL_NO_ERROR)){ printf("Errorsettingupframebuffersfortest.\n"); returnfalse; } returnpass; }Example#20ShowfileFile: SuzanneGL.cpp Project: gpanic/3dApivoidSuzanneGL::RenderShadowMaps() { GLuintFramebufferName=0; glCreateFramebuffers(1,&FramebufferName); glBindFramebuffer(GL_FRAMEBUFFER,FramebufferName); glm::mat4depthViewProjectionMatrices[NUMBER_OF_LIGHTS]; for(inti=0;i(-10,10,-10,10,-10,20); glm::mat4depthViewMatrix=glm::lookAt(lightDir,glm::vec3(0,0,0),glm::vec3(0,1,0)); depthViewProjectionMatrices[i]=depthProjectionMatrix*depthViewMatrix; shadowModelMatrixIndex=glGetUniformLocation(shadowShaderProgram,"modelMatrix"); shadowViewProjectionMatrixIndex=glGetUniformLocation(shadowShaderProgram,"viewProjectionMatrix"); glProgramUniformMatrix4fv(shadowShaderProgram,shadowViewProjectionMatrixIndex,1,GL_FALSE,glm::value_ptr(depthViewProjectionMatrices[i])); for(ModelGLmodel:models) { glProgramUniformMatrix4fv(shadowShaderProgram,shadowModelMatrixIndex,1,GL_FALSE,glm::value_ptr(model.modelMatrix)); glNamedBufferSubData(materialBuffer,0,sizeof(Material),&model.material); glBindVertexArray(model.vertexArray); glUseProgram(shadowShaderProgram); glDrawArrays(GL_TRIANGLES,0,model.vertexCount); } } glBindFramebuffer(GL_FRAMEBUFFER,0); glm::mat4biasMatrix( 0.5,0.0,0.0,0.0, 0.0,0.5,0.0,0.0, 0.0,0.0,0.5,0.0, 0.5,0.5,0.5,1.0 ); shadowViewProjectionMatrixIndex=glGetUniformLocation(shaderProgram,"shadowViewProjectionMatrix"); shadowBiasMatrixIndex=glGetUniformLocation(shaderProgram,"shadowBiasMatrix"); glProgramUniformMatrix4fv(shaderProgram,shadowViewProjectionMatrixIndex,2,GL_FALSE,glm::value_ptr(depthViewProjectionMatrices[0])); glProgramUniformMatrix4fv(shaderProgram,shadowBiasMatrixIndex,1,GL_FALSE,glm::value_ptr(biasMatrix)); }Example#30ShowfileFile: IMaterial.cpp Project: mekchi/dream_v01boolIMaterial::FrameBufferInit() { GLintviewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); m_fViewportWidth=viewport[2]; m_fViewportHeight=viewport[3]; glGenFramebuffers(1,&m_gFB); glBindFramebuffer(GL_FRAMEBUFFER,m_gFB); glGenTextures(1,&m_gMainTexFrameBuffer); glBindTexture(GL_TEXTURE_2D,m_gMainTexFrameBuffer); 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,m_fViewportWidth,m_fViewportHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,0); //glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_gMainTexFrameBuffer,0); glBindTexture(GL_TEXTURE_2D,0); glGenRenderbuffers(1,&m_gRB); glBindRenderbuffer(GL_RENDERBUFFER,m_gRB); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8_OES,m_fViewportWidth,m_fViewportHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,m_gRB); glGenRenderbuffers(1,&m_gRBDepth); glBindRenderbuffer(GL_RENDERBUFFER,m_gRBDepth); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,m_fViewportWidth,m_fViewportHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_gRBDepth); glBindRenderbuffer(GL_RENDERBUFFER,0); //glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LESS); //glDepthMask(GL_TRUE); //glDepthRangef(0.0f,1.0f); //glClearDepthf(1.0f); glClearColor(1.0f,0.0f,0.0f,1.0f); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE) { __LOG("Faildtocreateframebuffer"); returnfalse; } glGenVertexArraysOES(1,&m_gVAO); glBindVertexArrayOES(m_gVAO); glGenBuffers(1,&m_gVBO); glBindBuffer(GL_ARRAY_BUFFER,m_gVBO); glBufferData(GL_ARRAY_BUFFER,sizeof(quad),quad,GL_STATIC_DRAW); glEnableVertexAttribArray(SAL_POSITION); glVertexAttribPointer(SAL_POSITION,3,GL_FLOAT,GL_FALSE,sizeof(float_t)*5,0); glEnableVertexAttribArray(SAL_TEXTURE_COORD); glVertexAttribPointer(SAL_TEXTURE_COORD,2,GL_FLOAT,GL_FALSE,sizeof(float_t)*5,(char*)NULL+(sizeof(float_t)*3)); glBindVertexArrayOES(0); glBindFramebuffer(GL_FRAMEBUFFER,Globals::GetDefaultFramebuffer()); //glBindFramebuffer(GL_FRAMEBUFFER,m_gFB); returntrue; }Example#40ShowfileFile: texture_interface.cpp Project: TechnoCrunch/ReGekko/** *Createanewtextureinthebackendrenderer *@paramactive_texture_unitActivetextureunittobindtoforcreation *@paramcache_entryCacheEntrytocreatetexturefor *@paramraw_dataRawtexturedata *@returnapointertoCacheEntry::BackendDatawithrenderer-specifictexturedata */ TextureManager::CacheEntry::BackendData*TextureInterface::Create(intactive_texture_unit, constTextureManager::CacheEntry&cache_entry,u8*raw_data){ BackendData*backend_data=newBackendData(); glActiveTexture(GL_TEXTURE0+active_texture_unit); switch(cache_entry.type_){ //NormaltexturefromRAM caseTextureManager::kSourceType_Normal: glGenTextures(1,&backend_data->color_texture_); glBindTexture(GL_TEXTURE_2D,backend_data->color_texture_); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,cache_entry.width_,cache_entry.height_,0, GL_RGBA,GL_UNSIGNED_BYTE,raw_data); break; //TextureistheresultofanEFBcopy caseTextureManager::kSourceType_EFBCopy: { GLuinttextures[2]; glGenTextures(2,textures); backend_data->color_texture_=textures[0]; backend_data->depth_texture_=textures[1]; backend_data->is_depth_copy=(cache_entry.efb_copy_data_.pixel_format_==gp::kPixelFormat_Z24); //Createthecolorcomponenttexture glBindTexture(GL_TEXTURE_2D,backend_data->color_texture_); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,cache_entry.width_,cache_entry.height_,0, GL_RGBA,GL_UNSIGNED_BYTE,NULL); glBindTexture(GL_TEXTURE_2D,0); //Createthedepthcomponenttexture glBindTexture(GL_TEXTURE_2D,backend_data->depth_texture_); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,cache_entry.width_, cache_entry.height_,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,NULL); glBindTexture(GL_TEXTURE_2D,0); //CreatetheFBOandattachcolor/depthtextures glGenFramebuffers(1,&backend_data->efb_framebuffer_);//Generateframebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER,backend_data->efb_framebuffer_); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, backend_data->color_texture_,0); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, backend_data->depth_texture_,0); //Checkforcompleteness GLenumres=glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); _ASSERT_MSG(TGP,GL_FRAMEBUFFER_COMPLETE==res,"couldn'tOpenGLEFBcopyFBO!"); ////////////////////// /*glBindFramebuffer(GL_READ_FRAMEBUFFER,backend_data->efb_framebuffer_); glReadBuffer(GL_COLOR_ATTACHMENT0); staticu8raw_data[1024*1024*4]; staticintnum=0; num++; glBindFramebuffer(GL_READ_FRAMEBUFFER,parent_->fbo_[RendererBase::kFramebuffer_EFB]); glReadBuffer(GL_DEPTH_ATTACHMENT); glReadPixels(0,0,cache_entry.width_,cache_entry.height_,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,raw_data); //OptionallydumptexturetoTGA... if(1){ std::stringfilepath=common::g_config->program_dir()+std::string("/dump/efb-copies/"); common::CreateFullPath(filepath); filepath=common::FormatStr("%s/%08x_%d.tga",filepath.c_str(),gp::g_bp_regs.efb_copy_addr<<5,num); video_core::DumpTGA(filepath,cache_entry.width_,cache_entry.height_,raw_data); } glBindFramebuffer(GL_READ_FRAMEBUFFER,0); */ ////////////////////////////// //RebindEFB glBindFramebuffer(GL_DRAW_FRAMEBUFFER,parent_->fbo_[RendererBase::kFramebuffer_EFB]); } break; //Unknowntexturesource default: _ASSERT_MSG(TGP,0,"Unknowntexturesource%d",(int)cache_entry.type_); break; } returnbackend_data; }Example#50ShowfileFile: point_shadows.cpp Project: Crystal521/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); glEnable(GL_CULL_FACE); //Setupandcompileourshaders Shadershader("point_shadows.vs","point_shadows.frag"); ShadersimpleDepthShader("point_shadows_depth.vs","point_shadows_depth.frag","point_shadows_depth.gs"); //Settexturesamples shader.Use(); glUniform1i(glGetUniformLocation(shader.Program,"diffuseTexture"),0); glUniform1i(glGetUniformLocation(shader.Program,"depthMap"),1); //Lightsource glm::vec3lightPos(0.0f,0.0f,0.0f); //Loadtextures woodTexture=loadTexture(FileSystem::getPath("resources/textures/wood.png").c_str()); //ConfiguredepthmapFBO constGLuintSHADOW_WIDTH=1024,SHADOW_HEIGHT=1024; GLuintdepthMapFBO; glGenFramebuffers(1,&depthMapFBO); //Createdepthcubemaptexture GLuintdepthCubemap; glGenTextures(1,&depthCubemap); glBindTexture(GL_TEXTURE_CUBE_MAP,depthCubemap); for(GLuinti=0;i<6;++i) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,GL_DEPTH_COMPONENT,SHADOW_WIDTH,SHADOW_HEIGHT,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE); //AttachcubemapasdepthmapFBO'scolorbuffer glBindFramebuffer(GL_FRAMEBUFFER,depthMapFBO); glFramebufferTexture(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,depthCubemap,0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE) std::cout<shadowTransforms; shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(1.0,0.0,0.0),glm::vec3(0.0,-1.0,0.0))); shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(-1.0,0.0,0.0),glm::vec3(0.0,-1.0,0.0))); shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(0.0,1.0,0.0),glm::vec3(0.0,0.0,1.0))); shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(0.0,-1.0,0.0),glm::vec3(0.0,0.0,-1.0))); shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(0.0,0.0,1.0),glm::vec3(0.0,-1.0,0.0))); shadowTransforms.push_back(shadowProj*glm::lookAt(lightPos,lightPos+glm::vec3(0.0,0.0,-1.0),glm::vec3(0.0,-1.0,0.0))); //1.Renderscenetodepthcubemap glViewport(0,0,SHADOW_WIDTH,SHADOW_HEIGHT); glBindFramebuffer(GL_FRAMEBUFFER,depthMapFBO); glClear(GL_DEPTH_BUFFER_BIT); simpleDepthShader.Use(); for(GLuinti=0;i<6;++i) glUniformMatrix4fv(glGetUniformLocation(simpleDepthShader.Program,("shadowTransforms["+std::to_string(i)+"]").c_str()),1,GL_FALSE,glm::value_ptr(shadowTransforms[i])); glUniform1f(glGetUniformLocation(simpleDepthShader.Program,"far_plane"),far); glUniform3fv(glGetUniformLocation(simpleDepthShader.Program,"lightPos"),1,&lightPos[0]); RenderScene(simpleDepthShader); glBindFramebuffer(GL_FRAMEBUFFER,0); //2.Rendersceneasnormal glViewport(0,0,SCR_WIDTH,SCR_HEIGHT); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); shader.Use(); glm::mat4projection=glm::perspective(camera.Zoom,(float)SCR_WIDTH/(float)SCR_HEIGHT,0.1f,100.0f); glm::mat4view=camera.GetViewMatrix(); glUniformMatrix4fv(glGetUniformLocation(shader.Program,"projection"),1,GL_FALSE,glm::value_ptr(projection)); glUniformMatrix4fv(glGetUniformLocation(shader.Program,"view"),1,GL_FALSE,glm::value_ptr(view)); //Setlightuniforms glUniform3fv(glGetUniformLocation(shader.Program,"lightPos"),1,&lightPos[0]); glUniform3fv(glGetUniformLocation(shader.Program,"viewPos"),1,&camera.Position[0]); //Enable/Disableshadowsbypressing'SPACE' glUniform1i(glGetUniformLocation(shader.Program,"shadows"),shadows); glUniform1f(glGetUniformLocation(shader.Program,"far_plane"),far); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,woodTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_CUBE_MAP,depthCubemap); RenderScene(shader); //Swapthebuffers glfwSwapBuffers(window); } glfwTerminate(); return0; }Example#60ShowfileFile: GraphicsContext3DQt.cpp Project: xiaolu31/webkit-nodevoidGraphicsContext3D::reshape(intwidth,intheight) { if((width==m_currentWidth&&height==m_currentHeight)||(!m_private)) return; m_currentWidth=width; m_currentHeight=height; makeContextCurrent(); //Createcolorbuffer glBindTexture(GraphicsContext3D::TEXTURE_2D,m_texture); if(m_attrs.alpha) glTexImage2D(GraphicsContext3D::TEXTURE_2D,/*level*/0,GraphicsContext3D::RGBA,width,height,/*border*/0,GraphicsContext3D::RGBA,GraphicsContext3D::UNSIGNED_BYTE,/*data*/0); else glTexImage2D(GraphicsContext3D::TEXTURE_2D,/*level*/0,GraphicsContext3D::RGB,width,height,/*border*/0,GraphicsContext3D::RGB,GraphicsContext3D::UNSIGNED_BYTE,/*data*/0); glBindTexture(GraphicsContext3D::TEXTURE_2D,0); //Createdepthandstencilbuffers. #ifdefined(QT_OPENGL_ES_2) if(m_attrs.depth){ glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,m_depthBuffer); glRenderbufferStorage(GraphicsContext3D::RENDERBUFFER,GraphicsContext3D::DEPTH_COMPONENT16,width,height); glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,0); } if(m_attrs.stencil){ glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,m_stencilBuffer); glRenderbufferStorage(GraphicsContext3D::RENDERBUFFER,GraphicsContext3D::STENCIL_INDEX8,width,height); glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,0); } #else if(m_attrs.depth||m_attrs.stencil){ glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,m_depthStencilBuffer); if(m_attrs.depth&&m_attrs.stencil) glRenderbufferStorage(GraphicsContext3D::RENDERBUFFER,GL_DEPTH24_STENCIL8,width,height); elseif(m_attrs.depth) glRenderbufferStorage(GraphicsContext3D::RENDERBUFFER,GraphicsContext3D::DEPTH_COMPONENT,width,height); elseif(m_attrs.stencil) glRenderbufferStorage(GraphicsContext3D::RENDERBUFFER,GraphicsContext3D::STENCIL_INDEX,width,height); glBindRenderbuffer(GraphicsContext3D::RENDERBUFFER,0); } #endif //ConstructcanvasFBO. glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER,m_fbo); glFramebufferTexture2D(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::COLOR_ATTACHMENT0,GraphicsContext3D::TEXTURE_2D,m_texture,0); #ifdefined(QT_OPENGL_ES_2) if(m_attrs.depth) glFramebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::DEPTH_ATTACHMENT,GraphicsContext3D::RENDERBUFFER,m_depthBuffer); if(m_attrs.stencil) glFramebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::STENCIL_ATTACHMENT,GraphicsContext3D::RENDERBUFFER,m_stencilBuffer); #else if(m_attrs.depth&&m_attrs.stencil) glFramebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT,GraphicsContext3D::RENDERBUFFER,m_depthStencilBuffer); elseif(m_attrs.depth) glFramebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::DEPTH_ATTACHMENT,GraphicsContext3D::RENDERBUFFER,m_depthStencilBuffer); elseif(m_attrs.stencil) glFramebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER,GraphicsContext3D::STENCIL_ATTACHMENT,GraphicsContext3D::RENDERBUFFER,m_depthStencilBuffer); #endif GLenumstatus=glCheckFramebufferStatus(GraphicsContext3D::FRAMEBUFFER); if(status!=GraphicsContext3D::FRAMEBUFFER_COMPLETE){ LOG_ERROR("GraphicsContext3D:CanvasFBOinitializationfailed."); return; } intclearFlags=GraphicsContext3D::COLOR_BUFFER_BIT; if(m_attrs.depth) clearFlags|=GraphicsContext3D::DEPTH_BUFFER_BIT; if(m_attrs.stencil) clearFlags|=GraphicsContext3D::STENCIL_BUFFER_BIT; glClear(clearFlags); glFlush(); }Example#70ShowfileFile: test.cpp Project: flamingfox/Gamagora-Rendu_temps_reel-TPvoidinit() { //std::stringracineProjet="C:/Users/etu/workspace/code/Rendutempsreel/"; std::stringracineProjet="C:/Users/etu/Documents/GitHub/Gamagora-Rendu_temps_reel-TP/"; //std::stringracineProjet="B:/Utilisateur/git/code/Gamagora-Rendu_temps_reel-TP/"; //BuildourprogramandanemptyVAO gs.programView=buildProgram((racineProjet+(std::string)"basic.vsl").c_str(),(racineProjet+(std::string)"basic.fsl").c_str()); Meshm; m=ObjManager::loadFromOBJ(Vector3D(0,0,0),(racineProjet+(std::string)"monkey.obj").c_str()); nbVertex=m.nbface()+6;//nbface+quad"sol" float*data=(float*)malloc(nbVertex*4*sizeof(float)); float*dataNormal=(float*)malloc(nbVertex*4*sizeof(float)); std::vectorvertex=m.getvertex(); std::vectorface=m.getface(); std::vectornormals=m.getNormals(); std::vectornormalIds=m.getNormalIds(); inti=0; for(intj=0;jGetFD(),width,height,GBM_FORMAT_XRGB8888,&handle, &stride,&offset,&framebuffer.fb_id,0); if(!framebuffer.fb_id){ fprintf(stderr,"failedtocreateframebufferfrombufferobject.\n"); returnfalse; } constEGLintkhr_image_attrs[]={EGL_DMA_BUF_PLANE0_FD_EXT, framebuffer.fd, EGL_WIDTH, width, EGL_HEIGHT, height, EGL_LINUX_DRM_FOURCC_EXT, GBM_FORMAT_XRGB8888, EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast(stride), EGL_DMA_BUF_PLANE0_OFFSET_EXT, static_cast(offset), EGL_NONE}; framebuffer.image= egl_.CreateImageKHR(egl_.display,EGL_NO_CONTEXT,EGL_LINUX_DMA_BUF_EXT, nullptr/*noclientbuffer*/,khr_image_attrs); if(framebuffer.image==EGL_NO_IMAGE_KHR){ fprintf(stderr,"failedtomakeimagefrombufferobject:%s\n", EglGetError()); returnfalse; } glGenTextures(1,&framebuffer.gl_tex); glBindTexture(GL_TEXTURE_2D,framebuffer.gl_tex); egl_.EGLImageTargetTexture2DOES(GL_TEXTURE_2D,framebuffer.image); glBindTexture(GL_TEXTURE_2D,0); glGenFramebuffers(1,&framebuffer.gl_fb); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer.gl_fb); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, framebuffer.gl_tex,0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE){ fprintf(stderr, "failedframebuffercheckforcreatedtargetbuffer:%x\n", glCheckFramebufferStatus(GL_FRAMEBUFFER)); glDeleteFramebuffers(1,&framebuffer.gl_fb); glDeleteTextures(1,&framebuffer.gl_tex); returnfalse; } returntrue; }Example#100ShowfilevoidRenderTarget::Activate() { glBindFramebuffer(GL_FRAMEBUFFER,fbo); if(targets.size()) { glDrawBuffers(targets.size(),buffers); for(size_ti=0;iSetAsAttachment(i); } } if(cvx!=vx||cvy!=vy||cvw!=vw||cvh!=vh) { cvx=vx; cvy=vy; cvw=vw; cvh=vh; glViewport(vx,vy,vw,vh); } interr=glCheckFramebufferStatus(GL_FRAMEBUFFER); switch(err) { caseGL_FRAMEBUFFER_COMPLETE:break; caseGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:Fatal("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n");break; caseGL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:Fatal("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS\n");break; caseGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:Fatal("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n");break; caseGL_FRAMEBUFFER_UNSUPPORTED:Fatal("GL_FRAMEBUFFER_UNSUPPORTED\n");break; caseGL_INVALID_FRAMEBUFFER_OPERATION:Fatal("GL_INVALID_FRAMEBUFFER_OPERATION\n");break; caseGL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB:Fatal("GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB\n");break; caseGL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB:Fatal("GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB\n");break; default:Fatal("Unknownframebuffererror");break; } if(depth) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } staticBlendModecurrentBlendFunc=Overwrite; switch(blendmode) { caseOverwrite: glDisable(GL_BLEND); break; caseAlphablend: if(currentBlendFunc!=Alphablend) { currentBlendFunc=Alphablend; glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); } glEnable(GL_BLEND); break; caseAdditive: if(currentBlendFunc!=Additive) { currentBlendFunc=Additive; glBlendFunc(GL_ONE,GL_ONE); } glEnable(GL_BLEND); break; } }Example#110ShowfileFile: state_game.c Project: nativeAndroid/Blocksvoid state_game_init(void*ptr) { if(!world_is_initalized()) { error("state_gamestartedbeforeworld_init()"); state_queue_fail(); return; } pos=world_get_player(); state_window_get_size(&windoww,&windowh); //loadshaders'nstuff gl_program_load_file(&drawprogram,"shaders/vs","shaders/fs"); gl_program_load_file(&ppprogram,"shaders/pvs","shaders/pfs"); modelmatrix=glGetUniformLocation(drawprogram,"MODEL"); viewprojectionmatrix=glGetUniformLocation(drawprogram,"VP"); postprocess_uniform_tex=glGetUniformLocation(ppprogram,"tex"); postprocess_uniform_depth=glGetUniformLocation(ppprogram,"depth"); postprocess_uniform_window_szie=glGetUniformLocation(ppprogram,"window_size"); //generatethepostprocessingframebuffer glGenFramebuffers(1,&renderbuffer.framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,renderbuffer.framebuffer); glGenTextures(1,&renderbuffer.colorbuffer); glGenTextures(1,&renderbuffer.depthbuffer); glBindTexture(GL_TEXTURE_2D,renderbuffer.colorbuffer); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,windoww,windowh,0,GL_RGB,GL_FLOAT,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D,renderbuffer.depthbuffer); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,windoww,windowh,0,GL_DEPTH_COMPONENT,GL_FLOAT,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,renderbuffer.colorbuffer,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,renderbuffer.depthbuffer,0); //putthetexturesinthrrightspots glUseProgram(ppprogram); GLuinttex=glGetUniformLocation(ppprogram,"tex"); GLuintdepth=glGetUniformLocation(ppprogram,"depth"); glUniform1i(tex,0); glUniform1i(depth,1); //generatethepostprocessingmesh GLfloatmesh[]={ -1.0f,1.0f, -1.0f,-1.0f, 1.0f,-1.0f, 1.0f,1.0f, -1.0f,1.0f, 1.0f,-1.0f }; glGenBuffers(1,&pppointbuffer); glBindBuffer(GL_ARRAY_BUFFER,pppointbuffer); glBufferData(GL_ARRAY_BUFFER,sizeof(mesh)*sizeof(GLfloat),mesh,GL_STATIC_DRAW); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE) fail("BadFramebuffer"); rotx=0; roty=0; posptr=entity_pos_get_ptr(pos); vec3_tfriction={PLAYER_FRICTION,PLAYER_FRICTION,PLAYER_FRICTION}; entity_friction_set(pos,friction); state_mouse_center(); SDL_ShowCursor(0); ticks=SDL_GetTicks(); updatesem=SDL_CreateSemaphore(0); updatethread=SDL_CreateThread(updatethreadfunc,"updatethread",0); textbox_fps=textbox_create(10,10,200,100,"0fps",0,TEXTBOX_FONT_ROBOTO_REGULAR,TEXTBOX_FONT_SIZE_MEDIUM,0); }Example#120ShowfileFile: gbuffer.cpp Project: ArturSoczek/OpenGLInsightsCode //-------------------------------------------------------------------------- GBuffer::GBuffer( unsignedint_width, unsignedint_height) { //InitializeG-Buffertextures positionTex.Allocate(GL_RGBA32F,_width,_height); normalTex.Allocate(GL_RGBA16F,_width,_height); diffuseTex.Allocate(GL_RGBA16F,_width,_height); depthTex.Allocate(GL_DEPTH32F_STENCIL8,_width,_height); positionTex.SetWrapping(GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE); normalTex.SetWrapping(GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE); diffuseTex.SetWrapping(GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE); depthTex.SetWrapping(GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE); //Initializeframebuffer intoutPosition =0; intoutDiffuseSpecular =1; intoutNormalRoughness =2; glGenFramebuffers(1,&framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); //Attachoutputtextures glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+outPosition,positionTex.target,positionTex.id,0); glf::CheckFramebuffer(framebuffer); glBindTexture(diffuseTex.target,diffuseTex.id); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+outDiffuseSpecular,diffuseTex.target,diffuseTex.id,0); glf::CheckFramebuffer(framebuffer); glBindTexture(normalTex.target,normalTex.id); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+outNormalRoughness,normalTex.target,normalTex.id,0); glf::CheckFramebuffer(framebuffer); glBindTexture(depthTex.target,depthTex.id); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,depthTex.target,depthTex.id,0); glf::CheckFramebuffer(framebuffer); GLenumdrawBuffers[3]={GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1,GL_COLOR_ATTACHMENT2}; glDrawBuffers(3,drawBuffers); assert(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE); glBindFramebuffer(GL_FRAMEBUFFER,0); //Programregularmesh ProgramOptionsregularOptions=ProgramOptions::CreateVSOptions(); regularOptions.AddDefine("GBUFFER", 1); regularOptions.AddDefine("OUT_POSITION", outPosition); regularOptions.AddDefine("OUT_DIFFUSE_SPECULAR", outDiffuseSpecular); regularOptions.AddDefine("OUT_NORMAL_ROUGHNESS", outNormalRoughness); regularRenderer.program.Compile(regularOptions.Append(LoadFile(directory::ShaderDirectory+"meshregular.vs")), regularOptions.Append(LoadFile(directory::ShaderDirectory+"meshregular.fs"))); regularRenderer.transformVar =regularRenderer.program["Transform"].location; regularRenderer.modelVar =regularRenderer.program["Model"].location; regularRenderer.diffuseTexUnit =regularRenderer.program["DiffuseTex"].unit; regularRenderer.normalTexUnit =regularRenderer.program["NormalTex"].unit; regularRenderer.roughnessVar =regularRenderer.program["Roughness"].location; regularRenderer.specularityVar =regularRenderer.program["Specularity"].location; glProgramUniform1i(regularRenderer.program.id,regularRenderer.program["DiffuseTex"].location,regularRenderer.diffuseTexUnit); glProgramUniform1i(regularRenderer.program.id,regularRenderer.program["NormalTex"].location,regularRenderer.normalTexUnit); //Programterrainmesh ProgramOptionsterrainOptions=ProgramOptions::CreateVSOptions(); terrainOptions.AddDefine("GBUFFER", 1); terrainOptions.AddDefine("OUT_POSITION", outPosition); terrainOptions.AddDefine("OUT_DIFFUSE_SPECULAR", outDiffuseSpecular); terrainOptions.AddDefine("OUT_NORMAL_ROUGHNESS", outNormalRoughness); terrainRenderer.program.Compile(terrainOptions.Append(LoadFile(directory::ShaderDirectory+"meshterrain.vs")), terrainOptions.Append(LoadFile(directory::ShaderDirectory+"meshterrain.cs")), terrainOptions.Append(LoadFile(directory::ShaderDirectory+"meshterrain.es")), terrainOptions.Append(LoadFile(directory::ShaderDirectory+"meshterrain.fs"))); terrainRenderer.transformVar =terrainRenderer.program["Transform"].location; terrainRenderer.diffuseTexUnit =terrainRenderer.program["DiffuseTex"].unit; terrainRenderer.normalTexUnit =terrainRenderer.program["NormalTex"].unit; terrainRenderer.heightTexUnit =terrainRenderer.program["HeightTex"].unit; terrainRenderer.roughnessVar =terrainRenderer.program["Roughness"].location; terrainRenderer.specularityVar =terrainRenderer.program["Specularity"].location; terrainRenderer.tileSizeVar =terrainRenderer.program["TileSize"].location; terrainRenderer.tileCountVar =terrainRenderer.program["TileCount"].location; terrainRenderer.tileOffsetVar =terrainRenderer.program["TileOffset"].location; terrainRenderer.projFactorVar =terrainRenderer.program["ProjFactor"].location; terrainRenderer.tessFactorVar =terrainRenderer.program["TessFactor"].location; terrainRenderer.heightFactorVar =terrainRenderer.program["HeightFactor"].location; terrainRenderer.tileFactorVar =terrainRenderer.program["TileFactor"].location; glProgramUniform1i(terrainRenderer.program.id,terrainRenderer.program["DiffuseTex"].location,terrainRenderer.diffuseTexUnit); glProgramUniform1i(terrainRenderer.program.id,terrainRenderer.program["NormalTex"].location,terrainRenderer.normalTexUnit); glProgramUniform1i(terrainRenderer.program.id,terrainRenderer.program["HeightTex"].location,terrainRenderer.heightTexUnit); glf::CheckError("GBuffer::GBuffer"); }Example#130ShowfileFile: Grid.cpp Project: xiaolizi521/GLUTartifactvoidGrid::initData() { D=2,Q=9; demo=0; //Inputhorizontalvelocity vx=Settings::root["vx"].asFloat(); //Inputverticalvelocity vy=Settings::root["vy"].asFloat(); //Inputdensityρ=rho rho=Settings::root["rho"].asFloat(); //Relaxationtimeτ=tau tau=Settings::root["tau"].asFloat(); //Wrapping hWrap=Settings::root["wrap"]["horizontal"].asBool(); vWrap=Settings::root["wrap"]["vertical"].asBool(); lattice.resize(Q*num); solid.resize(2); for(inti=0;iSetTexture(SOIL_load_OGL_texture(TEXTUREDIR"BarrenReds.JPG",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_MIPMAPS)); sceneShader=newShader(SHADERDIR"Test_03_TexturedVertex.glsl",SHADERDIR"Test_03_TexturedFragment.glsl"); boolsceneFlag=sceneShader->LinkProgram(); combineShader=newShader(SHADERDIR"Test_03_TexturedVertex.glsl",SHADERDIR"Test_10_ProcessFragment.glsl"); boolcombFlag=combineShader->LinkProgram(); if(!combineShader->LinkProgram()||!sceneShader->LinkProgram()||!heightMap->GetTexture()){ return; } SetTextureRepeating(heightMap->GetTexture(),true); //scenedepthtexture glGenTextures(1,&bufferDepthTex); glBindTexture(GL_TEXTURE_2D,bufferDepthTex); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH24_STENCIL8,width,height,0,GL_DEPTH_STENCIL,GL_UNSIGNED_INT_24_8,NULL); //colourtexture for(inti=0;i<2;++i){ glGenTextures(1,&bufferColourTex[i]); glBindTexture(GL_TEXTURE_2D,bufferColourTex[i]); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); } glGenTextures(1,&debugColorTex); glBindTexture(GL_TEXTURE_2D,debugColorTex); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,800,600,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); //setupbufferforscenerenderingandpostprocessing glGenFramebuffers(1,&bufferFBO); glGenFramebuffers(1,&processFBO); glGenFramebuffers(1,&debugbufferFBO); glBindFramebuffer(GL_FRAMEBUFFER,bufferFBO); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,bufferDepthTex,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_TEXTURE_2D,bufferDepthTex,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,bufferColourTex[0],0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE||!bufferDepthTex||!bufferColourTex[0]){ return; } glBindFramebuffer(GL_FRAMEBUFFER,0); glEnable(GL_DEPTH_TEST); init=true; }Example#160ShowfileFile: map.cpp Project: psde/GBHMap::Map(constchar*map,Style*style){ this->style=style; Filereader*reader=newFilereader(map); Chunk*animation_data; Chunk*dmap_data; Chunk*chk; while((chk=reader->getNextChunk())){ if(strncmp(chk->header->type,"ANIM",4)==0){ animation_data=chk; } if(strncmp(chk->header->type,"DMAP",4)==0){ dmap_data=chk; } } //Readanimationdata char*starting=animation_data->data; char*offset=animation_data->data; while((int)offset-(int)startingheader->size) { TileAnimationanim; anim.base=*reinterpret_cast(offset); offset+=sizeof(short); anim.frame_rate=*reinterpret_cast(offset); offset+=sizeof(char); anim.repeat=*reinterpret_cast(offset); offset+=sizeof(unsignedchar); anim.anim_length=*reinterpret_cast(offset); offset+=sizeof(char); //unusedcharinfilestructure offset+=sizeof(char); anim.tiles=reinterpret_cast(offset); offset+=anim.anim_length*sizeof(short); std::vectoranimationTiles; for(inti=0;idata; c_map.base=reinterpret_cast(offset); offset+=256*256*sizeof(int); c_map.column_words=*reinterpret_cast(offset); offset+=sizeof(int); c_map.columns=reinterpret_cast(offset); offset+=c_map.column_words*sizeof(int); c_map.num_blocks=*reinterpret_cast(offset); offset+=sizeof(int); c_map.blocks=reinterpret_cast(offset); offset+=c_map.num_blocks*sizeof(BlockInfo); for(intx=0;x<255;x++)for(inty=0;y<255;y++) { intbase=c_map.base[y*256+x]; ColInfo*column=reinterpret_cast(c_map.columns+base); inti=0; for(i=0;iheight-column->offset);i++){ this->addBlock(c_map.blocks[column->blockd[i]],Vector3(x,-y,i+column->offset)); } } deletereader; GLenumFBOstatus; glGenTextures(1,&depthTextureId); glBindTexture(GL_TEXTURE_2D,depthTextureId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_MODE,GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_FUNC,GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D,GL_DEPTH_TEXTURE_MODE,GL_INTENSITY); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,shadowMapWidth,shadowMapHeight,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,0); glBindTexture(GL_TEXTURE_2D,0); glGenFramebuffers(1,&fboId); glBindFramebuffer(GL_FRAMEBUFFER,fboId); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,depthTextureId,0); FBOstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(FBOstatus!=GL_FRAMEBUFFER_COMPLETE) { std::cout<fn){ caseglfnUNDEFINED: abort();//badglfn break; caseglfnActiveTexture: glActiveTexture((GLenum)args->a0); break; caseglfnAttachShader: glAttachShader((GLint)args->a0,(GLint)args->a1); break; caseglfnBindAttribLocation: glBindAttribLocation((GLint)args->a0,(GLint)args->a1,(GLchar*)args->a2); free((void*)args->a2); break; caseglfnBindBuffer: glBindBuffer((GLenum)args->a0,(GLuint)args->a1); break; caseglfnBindFramebuffer: glBindFramebuffer((GLenum)args->a0,(GLint)args->a1); break; caseglfnBindRenderbuffer: glBindRenderbuffer((GLenum)args->a0,(GLint)args->a1); break; caseglfnBindTexture: glBindTexture((GLenum)args->a0,(GLint)args->a1); break; caseglfnBlendColor: glBlendColor(*(GLfloat*)&args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3); break; caseglfnBlendEquation: glBlendEquation((GLenum)args->a0); break; caseglfnBlendEquationSeparate: glBlendEquationSeparate((GLenum)args->a0,(GLenum)args->a1); break; caseglfnBlendFunc: glBlendFunc((GLenum)args->a0,(GLenum)args->a1); break; caseglfnBlendFuncSeparate: glBlendFuncSeparate((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2,(GLenum)args->a3); break; caseglfnBufferData: glBufferData((GLenum)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2,(GLenum)args->a3); break; caseglfnBufferSubData: glBufferSubData((GLenum)args->a0,(GLint)args->a1,(GLsizeiptr)args->a2,(GLvoid*)args->a3); break; caseglfnCheckFramebufferStatus: ret=glCheckFramebufferStatus((GLenum)args->a0); break; caseglfnClear: glClear((GLenum)args->a0); break; caseglfnClearColor: glClearColor(*(GLfloat*)&args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3); break; caseglfnClearDepthf: glClearDepthf(*(GLfloat*)&args->a0); break; caseglfnClearStencil: glClearStencil((GLint)args->a0); break; caseglfnColorMask: glColorMask((GLboolean)args->a0,(GLboolean)args->a1,(GLboolean)args->a2,(GLboolean)args->a3); break; caseglfnCompileShader: glCompileShader((GLint)args->a0); break; caseglfnCompressedTexImage2D: glCompressedTexImage2D((GLenum)args->a0,(GLint)args->a1,(GLenum)args->a2,(GLint)args->a3,(GLint)args->a4,(GLint)args->a5,(GLsizeiptr)args->a6,(GLvoid*)args->a7); break; caseglfnCompressedTexSubImage2D: glCompressedTexSubImage2D((GLenum)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3,(GLint)args->a4,(GLint)args->a5,(GLenum)args->a6,(GLsizeiptr)args->a7,(GLvoid*)args->a8); break; caseglfnCopyTexImage2D: glCopyTexImage2D((GLenum)args->a0,(GLint)args->a1,(GLenum)args->a2,(GLint)args->a3,(GLint)args->a4,(GLint)args->a5,(GLint)args->a6,(GLint)args->a7); break; caseglfnCopyTexSubImage2D: glCopyTexSubImage2D((GLenum)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3,(GLint)args->a4,(GLint)args->a5,(GLint)args->a6,(GLint)args->a7); break; caseglfnCreateProgram: ret=glCreateProgram(); break; caseglfnCreateShader: ret=glCreateShader((GLenum)args->a0); break; caseglfnCullFace: glCullFace((GLenum)args->a0); break; caseglfnDeleteBuffer: glDeleteBuffers(1,(constGLuint*)(&args->a0)); break; caseglfnDeleteFramebuffer: glDeleteFramebuffers(1,(constGLuint*)(&args->a0)); break; caseglfnDeleteProgram: glDeleteProgram((GLint)args->a0); break; caseglfnDeleteRenderbuffer: glDeleteRenderbuffers(1,(constGLuint*)(&args->a0)); break; caseglfnDeleteShader: glDeleteShader((GLint)args->a0); break; caseglfnDeleteTexture: glDeleteTextures(1,(constGLuint*)(&args->a0)); break; caseglfnDepthFunc: glDepthFunc((GLenum)args->a0); break; caseglfnDepthMask: glDepthMask((GLboolean)args->a0); break; caseglfnDepthRangef: glDepthRangef(*(GLfloat*)&args->a0,*(GLfloat*)&args->a1); break; caseglfnDetachShader: glDetachShader((GLint)args->a0,(GLint)args->a1); break; caseglfnDisable: glDisable((GLenum)args->a0); break; caseglfnDisableVertexAttribArray: glDisableVertexAttribArray((GLint)args->a0); break; caseglfnDrawArrays: glDrawArrays((GLenum)args->a0,(GLint)args->a1,(GLint)args->a2); break; caseglfnDrawElements: glDrawElements((GLenum)args->a0,(GLint)args->a1,(GLenum)args->a2,(void*)args->a3); break; caseglfnEnable: glEnable((GLenum)args->a0); break; caseglfnEnableVertexAttribArray: glEnableVertexAttribArray((GLint)args->a0); break; caseglfnFinish: glFinish(); break; caseglfnFlush: glFlush(); break; caseglfnFramebufferRenderbuffer: glFramebufferRenderbuffer((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2,(GLint)args->a3); break; caseglfnFramebufferTexture2D: glFramebufferTexture2D((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2,(GLint)args->a3,(GLint)args->a4); break; caseglfnFrontFace: glFrontFace((GLenum)args->a0); break; caseglfnGenBuffer: glGenBuffers(1,(GLuint*)&ret); break; caseglfnGenFramebuffer: glGenFramebuffers(1,(GLuint*)&ret); break; caseglfnGenRenderbuffer: glGenRenderbuffers(1,(GLuint*)&ret); break; caseglfnGenTexture: glGenTextures(1,(GLuint*)&ret); break; caseglfnGenerateMipmap: glGenerateMipmap((GLenum)args->a0); break; caseglfnGetActiveAttrib: glGetActiveAttrib( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)args->a4, (GLenum*)args->a5, (GLchar*)args->a6); break; caseglfnGetActiveUniform: glGetActiveUniform( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)args->a4, (GLenum*)args->a5, (GLchar*)args->a6); break; caseglfnGetAttachedShaders: glGetAttachedShaders((GLuint)args->a0,(GLsizei)args->a1,(GLsizei*)args->a2,(GLuint*)args->a3); break; caseglfnGetAttribLocation: ret=glGetAttribLocation((GLint)args->a0,(GLchar*)args->a1); free((void*)args->a1); break; caseglfnGetBooleanv: glGetBooleanv((GLenum)args->a0,(GLboolean*)args->a1); break; caseglfnGetBufferParameteri: glGetBufferParameteriv((GLenum)args->a0,(GLenum)args->a1,(GLint*)&ret); break; caseglfnGetFloatv: glGetFloatv((GLenum)args->a0,(GLfloat*)args->a1); break; caseglfnGetIntegerv: glGetIntegerv((GLenum)args->a0,(GLint*)args->a1); break; caseglfnGetError: ret=glGetError(); break; caseglfnGetFramebufferAttachmentParameteriv: glGetFramebufferAttachmentParameteriv((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2,(GLint*)&ret); break; caseglfnGetProgramiv: glGetProgramiv((GLint)args->a0,(GLenum)args->a1,(GLint*)&ret); break; caseglfnGetProgramInfoLog: glGetProgramInfoLog((GLuint)args->a0,(GLsizei)args->a1,(GLsizei*)args->a2,(GLchar*)args->a3); break; caseglfnGetRenderbufferParameteriv: glGetRenderbufferParameteriv((GLenum)args->a0,(GLenum)args->a1,(GLint*)&ret); break; caseglfnGetShaderiv: glGetShaderiv((GLint)args->a0,(GLenum)args->a1,(GLint*)&ret); break; caseglfnGetShaderInfoLog: glGetShaderInfoLog((GLuint)args->a0,(GLsizei)args->a1,(GLsizei*)args->a2,(GLchar*)args->a3); break; caseglfnGetShaderPrecisionFormat: glGetShaderPrecisionFormat((GLenum)args->a0,(GLenum)args->a1,(GLint*)args->a2,(GLint*)args->a3); break; caseglfnGetShaderSource: glGetShaderSource((GLuint)args->a0,(GLsizei)args->a1,(GLsizei*)args->a2,(GLchar*)args->a3); break; caseglfnGetString: ret=(uintptr_t)glGetString((GLenum)args->a0); break; caseglfnGetTexParameterfv: glGetTexParameterfv((GLenum)args->a0,(GLenum)args->a1,(GLfloat*)args->a2); break; caseglfnGetTexParameteriv: glGetTexParameteriv((GLenum)args->a0,(GLenum)args->a1,(GLint*)args->a2); break; caseglfnGetUniformfv: glGetUniformfv((GLuint)args->a0,(GLint)args->a1,(GLfloat*)args->a2); break; caseglfnGetUniformiv: glGetUniformiv((GLuint)args->a0,(GLint)args->a1,(GLint*)args->a2); break; caseglfnGetUniformLocation: ret=glGetUniformLocation((GLint)args->a0,(GLchar*)args->a1); free((void*)args->a1); break; caseglfnGetVertexAttribfv: glGetVertexAttribfv((GLuint)args->a0,(GLenum)args->a1,(GLfloat*)args->a2); break; caseglfnGetVertexAttribiv: glGetVertexAttribiv((GLuint)args->a0,(GLenum)args->a1,(GLint*)args->a2); break; caseglfnHint: glHint((GLenum)args->a0,(GLenum)args->a1); break; caseglfnIsBuffer: ret=glIsBuffer((GLint)args->a0); break; caseglfnIsEnabled: ret=glIsEnabled((GLenum)args->a0); break; caseglfnIsFramebuffer: ret=glIsFramebuffer((GLint)args->a0); break; caseglfnIsProgram: ret=glIsProgram((GLint)args->a0); break; caseglfnIsRenderbuffer: ret=glIsRenderbuffer((GLint)args->a0); break; caseglfnIsShader: ret=glIsShader((GLint)args->a0); break; caseglfnIsTexture: ret=glIsTexture((GLint)args->a0); break; caseglfnLineWidth: glLineWidth(*(GLfloat*)&args->a0); break; caseglfnLinkProgram: glLinkProgram((GLint)args->a0); break; caseglfnPixelStorei: glPixelStorei((GLenum)args->a0,(GLint)args->a1); break; caseglfnPolygonOffset: glPolygonOffset(*(GLfloat*)&args->a0,*(GLfloat*)&args->a1); break; caseglfnReadPixels: glReadPixels((GLint)args->a0,(GLint)args->a1,(GLsizei)args->a2,(GLsizei)args->a3,(GLenum)args->a4,(GLenum)args->a5,(void*)args->a6); break; caseglfnReleaseShaderCompiler: glReleaseShaderCompiler(); break; caseglfnRenderbufferStorage: glRenderbufferStorage((GLenum)args->a0,(GLenum)args->a1,(GLint)args->a2,(GLint)args->a3); break; caseglfnSampleCoverage: glSampleCoverage(*(GLfloat*)&args->a0,(GLboolean)args->a1); break; caseglfnScissor: glScissor((GLint)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3); break; caseglfnShaderSource: #ifdefined(os_ios)||defined(os_osx) glShaderSource((GLuint)args->a0,(GLsizei)args->a1,(constGLchar*const*)args->a2,NULL); #else glShaderSource((GLuint)args->a0,(GLsizei)args->a1,(constGLchar**)args->a2,NULL); #endif free(*(void**)args->a2); free((void*)args->a2); break; caseglfnStencilFunc: glStencilFunc((GLenum)args->a0,(GLint)args->a1,(GLuint)args->a2); break; caseglfnStencilFuncSeparate: glStencilFuncSeparate((GLenum)args->a0,(GLenum)args->a1,(GLint)args->a2,(GLuint)args->a3); break; caseglfnStencilMask: glStencilMask((GLuint)args->a0); break; caseglfnStencilMaskSeparate: glStencilMaskSeparate((GLenum)args->a0,(GLuint)args->a1); break; caseglfnStencilOp: glStencilOp((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2); break; caseglfnStencilOpSeparate: glStencilOpSeparate((GLenum)args->a0,(GLenum)args->a1,(GLenum)args->a2,(GLenum)args->a3); break; caseglfnTexImage2D: glTexImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLsizei)args->a3, (GLsizei)args->a4, 0,//border (GLenum)args->a5, (GLenum)args->a6, (constGLvoid*)args->a7); break; caseglfnTexSubImage2D: glTexSubImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLsizei)args->a4, (GLsizei)args->a5, (GLenum)args->a6, (GLenum)args->a7, (constGLvoid*)args->a8); break; caseglfnTexParameterf: glTexParameterf((GLenum)args->a0,(GLenum)args->a1,*(GLfloat*)&args->a2); break; caseglfnTexParameterfv: glTexParameterfv((GLenum)args->a0,(GLenum)args->a1,(GLfloat*)args->a2); break; caseglfnTexParameteri: glTexParameteri((GLenum)args->a0,(GLenum)args->a1,(GLint)args->a2); break; caseglfnTexParameteriv: glTexParameteriv((GLenum)args->a0,(GLenum)args->a1,(GLint*)args->a2); break; caseglfnUniform1f: glUniform1f((GLint)args->a0,*(GLfloat*)&args->a1); break; caseglfnUniform1fv: glUniform1fv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform1i: glUniform1i((GLint)args->a0,(GLint)args->a1); break; caseglfnUniform1iv: glUniform1iv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform2f: glUniform2f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2); break; caseglfnUniform2fv: glUniform2fv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform2i: glUniform2i((GLint)args->a0,(GLint)args->a1,(GLint)args->a2); break; caseglfnUniform2iv: glUniform2iv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform3f: glUniform3f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3); break; caseglfnUniform3fv: glUniform3fv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform3i: glUniform3i((GLint)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3); break; caseglfnUniform3iv: glUniform3iv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform4f: glUniform4f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3,*(GLfloat*)&args->a4); break; caseglfnUniform4fv: glUniform4fv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniform4i: glUniform4i((GLint)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3,(GLint)args->a4); break; caseglfnUniform4iv: glUniform4iv((GLint)args->a0,(GLsizeiptr)args->a1,(GLvoid*)args->a2); break; caseglfnUniformMatrix2fv: glUniformMatrix2fv((GLint)args->a0,(GLsizeiptr)args->a1,0,(GLvoid*)args->a2); break; caseglfnUniformMatrix3fv: glUniformMatrix3fv((GLint)args->a0,(GLsizeiptr)args->a1,0,(GLvoid*)args->a2); break; caseglfnUniformMatrix4fv: glUniformMatrix4fv((GLint)args->a0,(GLsizeiptr)args->a1,0,(GLvoid*)args->a2); break; caseglfnUseProgram: glUseProgram((GLint)args->a0); break; caseglfnValidateProgram: glValidateProgram((GLint)args->a0); break; caseglfnVertexAttrib1f: glVertexAttrib1f((GLint)args->a0,*(GLfloat*)&args->a1); break; caseglfnVertexAttrib1fv: glVertexAttrib1fv((GLint)args->a0,(GLfloat*)args->a1); break; caseglfnVertexAttrib2f: glVertexAttrib2f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2); break; caseglfnVertexAttrib2fv: glVertexAttrib2fv((GLint)args->a0,(GLfloat*)args->a1); break; caseglfnVertexAttrib3f: glVertexAttrib3f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3); break; caseglfnVertexAttrib3fv: glVertexAttrib3fv((GLint)args->a0,(GLfloat*)args->a1); break; caseglfnVertexAttrib4f: glVertexAttrib4f((GLint)args->a0,*(GLfloat*)&args->a1,*(GLfloat*)&args->a2,*(GLfloat*)&args->a3,*(GLfloat*)&args->a4); break; caseglfnVertexAttrib4fv: glVertexAttrib4fv((GLint)args->a0,(GLfloat*)args->a1); break; caseglfnVertexAttribPointer: glVertexAttribPointer((GLuint)args->a0,(GLint)args->a1,(GLenum)args->a2,(GLboolean)args->a3,(GLsizei)args->a4,(constGLvoid*)args->a5); break; caseglfnViewport: glViewport((GLint)args->a0,(GLint)args->a1,(GLint)args->a2,(GLint)args->a3); break; } }Example#180ShowfileFile: rendertotexture.cpp Project: tinou98/TowerDefencerenderToTexture::renderToTexture(intwidth,intheight,booldepthTest,GLenumformat):width(width),height(height),depthTest(depthTest),format(format){ this->gen(); setupThrow(LOG,glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE,"Setupdone"); }Example#190ShowfileFile: GraphicsContext3DQt.cpp Project: xiaolu31/webkit-nodeGC3DenumGraphicsContext3D::checkFramebufferStatus(GC3Denumtarget) { makeContextCurrent(); returnglCheckFramebufferStatus(target); }Example#200ShowfileFile: ola_glrt.cpp Project: azykise/olaworkboolOlaGLRenderTarget::initialize(intw,inth) { release(); mWidth=w; mHeight=h; //colorbuffer unsignedintcolor_rb=0; glGenTextures(1,&color_rb); lgGLError("colorbuffergenfailedinrt\n"); glBindTexture(GL_TEXTURE_2D,color_rb); lgGLError("colorbufferbindfailedinrt\n"); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,mWidth,mHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,0);//rgbaGL_UNSIGNED_SHORT_5_6_5GL_UNSIGNED_BYTE lgGLError("colorbuffercreatefailedinrt\n"); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D,0); //depthbuffer unsignedintdepth_rb=0; glGenTextures(1,&depth_rb); lgGLError("depthbuffergenfailedinrt\n"); glBindTexture(GL_TEXTURE_2D,depth_rb); lgGLError("depthbufferbindfailedinrt\n"); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,mWidth,mHeight,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT,0);//rgbaGL_UNSIGNED_SHORT_5_6_5GL_UNSIGNED_BYTE lgGLError("depthbuffercreatefailedinrt\n"); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_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); glBindTexture(GL_TEXTURE_2D,0); //stencilbuffer //unsignedintstencel_buffer=0; //glGenRenderbuffers(1,&stencel_buffer); //glBindRenderbuffer(GL_RENDERBUFFER,stencel_buffer); //glRenderbufferStorage(GL_RENDERBUFFER,GL_STENCIL_INDEX8,mWidth,mHeight); //lgGLError("stencilbuffercreatefailedinrt\n"); //glBindRenderbuffer(GL_RENDERBUFFER,0); unsignedintfbo=0; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); lgGLError("framebuffergenfailedinrt\n"); mHandles[OlaRTParam::FRAME_BUFFER]=fbo; mHandles[OlaRTParam::COLOR_BUFFER]=color_rb; glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color_rb,0); lgGLError("colorbufferattachfailedinrt\n"); mHandles[OlaRTParam::DEPTH_BUFFER]=depth_rb; glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,depth_rb,0); lgGLError("depthbufferattachfailedinrt\n"); //mHandles[OlaRTParam::STENCIL_BUFFER]=stencel_buffer; //glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,stencel_buffer); //lgGLError("stencilbufferattachfailedinrt\n"); GLenumhr=glCheckFramebufferStatus(GL_FRAMEBUFFER); switch(hr) { caseGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: lg("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); break; caseGL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: lg("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS"); break; caseGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: lg("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"); break; caseGL_FRAMEBUFFER_UNSUPPORTED: lg("GL_FRAMEBUFFER_UNSUPPORTED"); break; caseGL_FRAMEBUFFER_COMPLETE: break; } glBindFramebuffer(GL_FRAMEBUFFER,0); returntrue; }Example#210ShowfileFile: DepthBuffer.cpp Project: BeardedPlatypus/nTiledDepthBuffer::DepthBuffer(unsignedintwidth,unsignedheight):width(width), height(height){ //CreateFBO //-------------------------------------------------------------------------- glGenFramebuffers(1,&(this->p_fbo)); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,this->p_fbo); //Createcolouroutputtexturebuffer //-------------------------------------------------------------------------- glGenTextures(1,&(this->p_colour_texture)); glBindTexture(GL_TEXTURE_2D,this->p_colour_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, this->width,this->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL ); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); //Attachtexturetheframebufferobject glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,//target GL_COLOR_ATTACHMENT0,//attachment GL_TEXTURE_2D,//textarget this->p_colour_texture,//texture 0//level(mipmaplevel) ); //Createdepthtexturebuffer //-------------------------------------------------------------------------- glGenTextures(1,&(this->p_depth_texture)); glBindTexture(GL_TEXTURE_2D,this->p_depth_texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 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_DEPTH_COMPONENT32F, this->width,this->height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL ); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, this->p_depth_texture, 0 ); //glDrawBuffer(GL_NONE); GLenumdraw_buffers[]={GL_COLOR_ATTACHMENT0}; glDrawBuffers(1,draw_buffers); GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status!=GL_FRAMEBUFFER_COMPLETE){ throwstd::runtime_error(std::string("FBerror,status:0x%x\n",status)); } glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0); }Example#220ShowfileFile: filter.cpp Project: DominikDeak/KFX/*--------------------------------------------------------------------------- Setupfunctionthataintialisesassets,matricesandotherOpenGL relatedstructureforrendering.NOTE:Thismustbecalledwithina validOpenGLcontext. ---------------------------------------------------------------------------*/ voidFilter::Setup(Buffers&Buffer) { Destroy(); if(!GLEW_ARB_framebuffer_object) {throwdexception("CurrentOpenGLcontextdoesnotsupportframebufferobjects.");} vector2uRes; switch(Select) { caseFilter::SelectVideo:Res=Buffer.GetVideoResolution();break; caseFilter::SelectDepth:Res=Buffer.GetDepthResolution();break; default:throwdexception("InvalidSelectenumeration.");; } if(Res.X<1||Res.Y<1){return;} //Createanewframebufferobject glGenFramebuffers(1,&FBOID); glBindFramebuffer(GL_FRAMEBUFFER,FBOID); //Createanewdepthbufferobject,thenassociatea //storagespaceforit,andattachittotheFBO glGenRenderbuffers(1,&DBOID); glBindRenderbuffer(GL_RENDERBUFFER,DBOID); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,Res.X,Res.Y); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,DBOID); //CreateacolourbufferinformofatextureandattachittotheFBO glGenTextures(1,&CBOID); glBindTexture(GL_TEXTURE_2D,CBOID); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,Res.X,Res.Y,0,GL_RGB,GL_UNSIGNED_BYTE,NULL); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,CBOID,0); //FBOtexturescaling glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_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); glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE); //Setupviewportsize ViewPort.Set4(0,0,Res.X,Res.Y); //Computefrustumaspectratiofromviewportsize Ratio.Set((float)ViewPort.C2,(float)ViewPort.C3); Ratio/=(float)Math::Min(ViewPort.C2,ViewPort.C3); //Defaultprojectionmatrix MP=MP.Identity(); MP=MP.Ortho(-Ratio.X,Ratio.X,-Ratio.Y,Ratio.Y,Near,Far); //Defaultmodelviewmatrix MV=MV.Identity(); MV=MV.Scale(Ratio.X,Ratio.Y,1.0f); //Defaulttexturematrix MT=MT.Identity(); //MT=MT.Scale(1.0f,-1.0f,1.0f); //MT=MT.Translate(0.0f,-1.0f,0.0f); MC=MC.Identity(); //Errorchecking GLenumError=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(Error!=GL_FRAMEBUFFER_COMPLETE){throwdexception("Failedtosetupframebufferobject:%s.",Debug::StatusFBO(Error));} Error=glGetError(); if(Error!=GL_NO_ERROR){throwdexception("OpenGLgeneratedanerror:%s",Debug::ErrorGL(Error));} }Example#230ShowfileFile: glframebuffer.cpp Project: BTML/colobotvoidCGLFramebuffer::Create() { if(m_fbo!=0)return; m_width=m_params.width; m_height=m_params.height; m_depth=m_params.depth; m_samples=m_params.samples; glGenFramebuffers(1,&m_fbo); glBindFramebuffer(GL_FRAMEBUFFER,m_fbo); //createcolortexture if(m_params.colorTexture) { GLintprevious; glGetIntegerv(GL_TEXTURE_BINDING_2D,&previous); glGenTextures(1,&m_colorTexture); glBindTexture(GL_TEXTURE_2D,m_colorTexture); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,m_params.width,m_params.height,0,GL_RGBA,GL_UNSIGNED_BYTE,nullptr); 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_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glBindTexture(GL_TEXTURE_2D,previous); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_colorTexture,0); } //createcolorrenderbuffer else { glGenRenderbuffers(1,&m_colorRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,m_colorRenderbuffer); if(m_params.samples>1) glRenderbufferStorageMultisample(GL_RENDERBUFFER,m_params.samples,GL_RGBA8,m_params.width,m_params.height); else glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8,m_params.width,m_params.height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,m_colorRenderbuffer); } GLuintdepthFormat=0; switch(m_params.depth) { case16:depthFormat=GL_DEPTH_COMPONENT16;break; case24:depthFormat=GL_DEPTH_COMPONENT24;break; case32:depthFormat=GL_DEPTH_COMPONENT32;break; default:depthFormat=GL_DEPTH_COMPONENT16;break; } //createdepthtexture if(m_params.depthTexture) { GLintprevious; glGetIntegerv(GL_TEXTURE_BINDING_2D,&previous); glGenTextures(1,&m_depthTexture); glBindTexture(GL_TEXTURE_2D,m_depthTexture); glTexImage2D(GL_TEXTURE_2D,0,depthFormat,m_params.width,m_params.height,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT,nullptr); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_MODE,GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_FUNC,GL_LEQUAL); floatcolor[]={1.0f,1.0f,1.0f,1.0f}; 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_WRAP_S,GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,color); glBindTexture(GL_TEXTURE_2D,previous); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,m_depthTexture,0); } //createdepthrenderbuffer else { glGenRenderbuffers(1,&m_depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,m_depthRenderbuffer); if(m_params.samples>1) glRenderbufferStorageMultisample(GL_RENDERBUFFER,m_params.samples,depthFormat,m_params.width,m_params.height); else glRenderbufferStorage(GL_RENDERBUFFER,depthFormat,m_params.width,m_params.height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_depthRenderbuffer); } GLuintresult=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(result!=GL_FRAMEBUFFER_COMPLETE) { GetLogger()->Error("Framebufferincomplete\n"); assert(false); } glBindFramebuffer(GL_FRAMEBUFFER,m_currentFBO); }Example#240ShowfileFile: opengl_window.cpp Project: FlibbleMr/neogfx voidopengl_window::render() { if(iRendering||processing_event()) return; uint64_tnow=app::instance().program_elapsed_ms(); if(iFrameRate!=boost::none&&now-iLastFrameTime<1000/*iFrameRate) return; if(!iEventHandler.native_window_ready_to_render()) return; rendering_check.trigger(); if(iInvalidatedRects.empty()) return; ++iFrameCounter; iRendering=true; iLastFrameTime=now; rendering.trigger(); rectinvalidatedRect=*iInvalidatedRects.begin(); for(constauto&ir:iInvalidatedRects) { invalidatedRect=invalidatedRect.combine(ir); } iInvalidatedRects.clear(); invalidatedRect.cx=std::min(invalidatedRect.cx,surface_size().cx-invalidatedRect.x); invalidatedRect.cy=std::min(invalidatedRect.cy,surface_size().cy-invalidatedRect.y); staticboolinitialized=false; if(!initialized) { rendering_engine().initialize(); initialized=true; } activate_context(); glCheck(glViewport(0,0,static_cast(extents().cx),static_cast(extents().cy))); glCheck(glMatrixMode(GL_PROJECTION)); glCheck(glLoadIdentity()); glCheck(glScalef(1.0,1.0,1.0)); glCheck(glMatrixMode(GL_MODELVIEW)); glCheck(glLoadIdentity()); constauto&logicalCoordinates=logical_coordinates(); glCheck(glOrtho(logicalCoordinates[0],logicalCoordinates[2],logicalCoordinates[1],logicalCoordinates[3],-1.0,1.0)); glCheck(glEnableClientState(GL_VERTEX_ARRAY)); glCheck(glEnableClientState(GL_COLOR_ARRAY)); glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); glCheck(glEnable(GL_TEXTURE_2D)); glCheck(glEnable(GL_MULTISAMPLE)); glCheck(glEnable(GL_BLEND)); if(iFrameBufferSize.cx(extents().cx)||iFrameBufferSize.cy(extents().cy)) { if(iFrameBufferSize!=size{}) { glCheck(glDeleteRenderbuffers(1,&iDepthStencilBuffer)); glCheck(glDeleteTextures(1,&iFrameBufferTexture)); glCheck(glDeleteFramebuffers(1,&iFrameBuffer)); } iFrameBufferSize=size( iFrameBufferSize.cx(iFrameBufferSize.cx),static_cast(iFrameBufferSize.cy),true)); glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D_MULTISAMPLE,iFrameBufferTexture,0)); glCheck(glGenRenderbuffers(1,&iDepthStencilBuffer)); glCheck(glBindRenderbuffer(GL_RENDERBUFFER,iDepthStencilBuffer)); glCheck(glRenderbufferStorageMultisample(GL_RENDERBUFFER,4,GL_DEPTH24_STENCIL8,static_cast(iFrameBufferSize.cx),static_cast(iFrameBufferSize.cy))); glCheck(glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,iDepthStencilBuffer)); glCheck(glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,iDepthStencilBuffer)); } else { glCheck(glBindFramebuffer(GL_FRAMEBUFFER,iFrameBuffer)); glCheck(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,iFrameBufferTexture)); glCheck(glBindRenderbuffer(GL_RENDERBUFFER,iDepthStencilBuffer)); } GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status!=GL_NO_ERROR&&status!=GL_FRAMEBUFFER_COMPLETE) throwfailed_to_create_framebuffer(status); glCheck(glBindFramebuffer(GL_FRAMEBUFFER,iFrameBuffer)); GLenumdrawBuffers[]={GL_COLOR_ATTACHMENT0}; glCheck(glDrawBuffers(sizeof(drawBuffers)/sizeof(drawBuffers[0]),drawBuffers)); glCheck(iEventHandler.native_window_render(invalidatedRect)); glCheck(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0)); glCheck(glBindFramebuffer(GL_READ_FRAMEBUFFER,iFrameBuffer)); glCheck(glBlitFramebuffer(0,0,static_cast(extents().cx),static_cast(extents().cy),0,0,static_cast(extents().cx),static_cast(extents().cy),GL_COLOR_BUFFER_BIT,GL_NEAREST)); display(); deactivate_context(); iRendering=false; rendering_finished.trigger(); }Example#250ShowfileFile: GLInterface.cpp Project: PhoenixOrg/PhoenixEngine EGBufferStatus::ValueCheckFramebufferStatus(constEGBuffer::ValueTarget) { constEGBufferStatus::ValueStatus=static_cast<:value>(glCheckFramebufferStatus(Target)); returnStatus; }Example#260ShowfileFile: Framebuffer.cpp Project: blair1618/stockvoidFramebuffer::prepare(RenderState&rs,GLuintunit){ m_colorTexture.prepare(rs,unit); //Generateframebufferhandle. CHECK_GL(glGenFramebuffers(1,&m_framebufferHandle)); if(m_options.hasDepth){ //Generatedepthbufferhandle. CHECK_GL(glGenRenderbuffers(1,&m_depthbufferHandle)); } if(m_options.hasStencil){ //Generatestencilbufferhandle. CHECK_GL(glGenRenderbuffers(1,&m_stencilbufferHandle)); } //Bindcolortexture. m_colorTexture.bind(rs,unit); if(m_options.hasDepth){ //Createdepthbufferstorage. CHECK_GL(glBindRenderbuffer(GL_RENDERBUFFER,m_depthbufferHandle)); CHECK_GL(glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,m_width,m_height)); } if(m_options.hasStencil){ //Createstencilbufferstorage. CHECK_GL(glBindRenderbuffer(GL_RENDERBUFFER,m_stencilbufferHandle)); CHECK_GL(glRenderbufferStorage(GL_RENDERBUFFER,GL_STENCIL_INDEX8,m_width,m_height)); } //Bindtheframebuffer. CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER,m_framebufferHandle)); //Attachthecolorbuffer. CHECK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_colorTexture.glHandle(),0)); if(m_options.hasDepth){ //Attachthedepthbuffer. CHECK_GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_depthbufferHandle)); } if(m_options.hasStencil){ //Attachthestencilbuffer. CHECK_GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,m_stencilbufferHandle)); } //Unbindrenderbufferobject. CHECK_GL(glBindRenderbuffer(GL_RENDERBUFFER,0)); //Checkframebufferstatus. GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); CHECK_GL(); //Bindthedefaultframebufferobject. CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER,0)); //Checkstatusanddisposeonfailure. if(status!=GL_FRAMEBUFFER_COMPLETE){ dispose(rs); switch(status){ caseGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: Log::e("Errorcreatingframebuffer:GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); break; caseGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: Log::e("Errorcreatingframebuffer:GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"); break; caseGL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: Log::e("Errorcreatingframebuffer:GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS"); break; caseGL_FRAMEBUFFER_UNSUPPORTED: Log::e("Errorcreatingframebuffer:GL_FRAMEBUFFER_UNSUPPORTED"); break; default: Log::e("Errorcreatingframebuffer:Unrecognizederror."); break; } } }Example#270ShowfileFile: IMaterial.cpp Project: mekchi/dream_v01boolCMaterialGlow::Init(SMaterialData*Data) { if(Data==nullptr) returnfalse; //staticfloat_tquad[30]= //{ //-1.0f,-1.0f,0.0f,0.0f,0.0f, //1.0f,-1.0f,0.0f,1.0f,0.0f, //1.0f,1.0f,0.0f,1.0f,1.0f, //-1.0f,-1.0f,0.0f,0.0f,0.0f, //1.0f,1.0f,0.0f,1.0f,1.0f, //-1.0f,1.0f,0.0f,0.0f,1.0f //}; GLintviewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); m_gTextureWidth=viewport[2]; m_gTextureHeight=viewport[3]; // //glGenTextures(1,&m_gTexture); // //glBindTexture(GL_TEXTURE_2D,m_gTexture); //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); // //if(!loadBmpImage(data->TextureFileName.c_str())) //returnfalse; glGenFramebuffers(1,&m_gFB); glGenRenderbuffers(1,&m_gRB); glGenTextures(2,m_gTexture); glBindTexture(GL_TEXTURE_2D,m_gTexture[0]); 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,m_gTextureWidth,m_gTextureHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,0); glBindTexture(GL_TEXTURE_2D,m_gTexture[1]); 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,m_gTextureWidth,m_gTextureHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,0); glBindTexture(GL_TEXTURE_2D,0); glBindRenderbuffer(GL_RENDERBUFFER,m_gRB); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8_OES,m_gTextureWidth,m_gTextureHeight); glBindRenderbuffer(GL_RENDERBUFFER,0); glBindFramebuffer(GL_FRAMEBUFFER,m_gFB); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,m_gRB); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE) { __LOG("Faildtocreateframebuffer"); returnfalse; } glBindFramebuffer(GL_FRAMEBUFFER,Globals::GetDefaultFramebuffer()); glGenVertexArraysOES(1,&m_gVAO); glBindVertexArrayOES(m_gVAO); glGenBuffers(1,&m_gVBO); glBindBuffer(GL_ARRAY_BUFFER,m_gVBO); glBufferData(GL_ARRAY_BUFFER,sizeof(quad),quad,GL_STATIC_DRAW); glEnableVertexAttribArray(SAL_POSITION); glVertexAttribPointer(SAL_POSITION,3,GL_FLOAT,GL_FALSE,sizeof(float_t)*5,0); glEnableVertexAttribArray(SAL_TEXTURE_COORD); glVertexAttribPointer(SAL_TEXTURE_COORD,2,GL_FLOAT,GL_FALSE,sizeof(float_t)*5,(char*)NULL+(sizeof(float_t)*3)); glBindVertexArrayOES(0); returntrue; }Example#280ShowfileFile: CCRenderTexture.cpp Project: HotWordland/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#290ShowfileFile: main.cpp Project: ButchDean/antons_opengl_tutorials_book/*initialisesecondaryframebuffer.thiswilljustallowustorenderourmain scenetoatextureinsteadofdirectlytothescreen.returnsfalseifsomething wentwrongintheframebuffercreation*/ boolinit_fb(){ glGenFramebuffers(1,&g_fb); /*createthetexturethatwillbeattachedtothefb.shouldbethesame dimensionsastheviewport*/ glGenTextures(1,&g_fb_tex); glBindTexture(GL_TEXTURE_2D,g_fb_tex); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, g_gl_width, g_gl_height, 0, GL_RGBA, 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_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); /*attachthetexturetotheframebuffer*/ glBindFramebuffer(GL_FRAMEBUFFER,g_fb); glFramebufferTexture2D( GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,g_fb_tex,0 ); /*createarenderbufferwhichallowsdepth-testingintheframebuffer*/ GLuintrb=0; glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage( GL_RENDERBUFFER,GL_DEPTH_COMPONENT,g_gl_width,g_gl_height ); /*attachrenderbuffertoframebuffer*/ glFramebufferRenderbuffer( GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,rb ); /*telltheframebuffertoexpectacolouroutputattachment(ourtexture)*/ GLenumdraw_bufs[]={GL_COLOR_ATTACHMENT0}; glDrawBuffers(1,draw_bufs); /*validatetheframebuffer-an'incomplete'errortellsusifaninvalid imageformatisattachedoriftheglDrawBuffersinformationisinvalid*/ GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(GL_FRAMEBUFFER_COMPLETE!=status){ fprintf(stderr,"ERROR:incompleteframebuffer\n"); if(GL_FRAMEBUFFER_UNDEFINED==status){ fprintf(stderr,"GL_FRAMEBUFFER_UNDEFINED\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER\n"); }elseif(GL_FRAMEBUFFER_UNSUPPORTED==status){ fprintf(stderr,"GL_FRAMEBUFFER_UNSUPPORTED\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE\n"); }elseif(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS==status){ fprintf(stderr,"GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS\n"); }else{ fprintf(stderr,"unspecifiederror\n"); } returnfalse; } /*re-bindthedefaultframebufferasasafeprecaution*/ glBindFramebuffer(GL_FRAMEBUFFER,0); returntrue; }Example#300ShowfileFile: CCRenderTexture.cpp Project: hyper123/MahjongboolRenderTexture::initWithWidthAndHeight(intw,inth,Texture2D::PixelFormatformat,GLuintdepthStencilFormat) { CCASSERT(format!=Texture2D::PixelFormat::A8,"onlyRGBandRGBAformatsarevalidforarendertexture"); boolret=false; void*data=nullptr; do { _fullRect=_rtTextureRect=Rect(0,0,w,h); //Sizesize=Director::getInstance()->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=newTexture2D(); 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=newTexture2D(); 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



請為這篇文章評分?