void ObjMeshGPUDeformer_uUq_pbuffer::BindRT() { if( !wglBindTexImageARB( pbuffer.hPBuffer, WGL_FRONT_LEFT_ARB ) ) { printf("Could not bind p-buffer to render texture."); throw 3; } }
void RenderTexture::BindTexture() { glBindTexture(m_texFormat, m_texID); if (!m_FBO) { if(!wglBindTexImageARB(m_hPBuffer, WGL_FRONT_LEFT_ARB )) { LOG_ERROR << "Could not bind PixelBuffer to render texture!"; } } }
void cPBuffer::Bind() { #ifdef WIN32 if(!wglBindTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB)) { Error("Error Binding pbuffer...\n"); } #elif defined(__linux__) #endif }
void OGLRenderTexture2D_ARB::Bind() { Super::Bind(); if( !wglBindTexImageARB( mPixelBuffer.mPBuffer, WGL_FRONT_LEFT_ARB ) ) { MessageBox(NULL,"Could not bind p-buffer to render texture!", "ERROR",MB_OK|MB_ICONEXCLAMATION); exit(-1); } }
int OglBindCamBuf (tCamera *pc) { if ((OglCamBufAvail (pc, 0) != 1) && !OglCreateCamBuf (pc)) return 0; OGL_BINDTEX (pc->glTexId); #if RENDER2TEXTURE == 1 # ifdef _WIN32 return pc->pb.bBound = wglBindTexImageARB (pc->pb.hBuf, WGL_FRONT_LEFT_ARB); # endif #endif return 1; }
Win32PBuffer::Win32PBuffer(PixelComponentType format, size_t width, size_t height): GLPBuffer(format, width, height), mContext(0) { createPBuffer(); // Create context mContext = new Win32Context(mHDC, mGlrc); #if 0 if(mUseBind) { // Bind texture glBindTextureEXT(GL_TEXTURE_2D, static_cast<GLTexture*>(mTexture.get())->getGLID()); wglBindTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB); } #endif }
void RenderPass::endPass() { // pop the viewport bit from beginPass() glPopAttrib(); if (m_bUsePBuffer) { // make the glut window's rendering context current and draw to the glut window. if (wglMakeCurrent(m_last_hdc, m_last_hglrc) == FALSE) wglGetLastError(); // bind the render target texture glBindTexture(GL_TEXTURE_2D, m_pFrameTexture->getGLTex()); // bind the pbuffer to the render texture object if (wglBindTexImageARB(m_pbuffer.getHPBuffer(), WGL_FRONT_LEFT_ARB) == FALSE) wglGetLastError(); } else { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); } }
//draw a frame void RenderFrame() { //Draw to pbuffer pbuffer.MakeCurrent(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //reset modelview matrix gluLookAt( 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); //Draw scene if(drawTextured) { glBindTexture(GL_TEXTURE_2D, decalTexture); glEnable(GL_TEXTURE_2D); glPushMatrix(); glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f); glutSolidTeapot(0.8f); glPopMatrix(); glDisable(GL_TEXTURE_2D); } else { glPushMatrix(); glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f); glRotatef(55.0f, 1.0f, 0.0f, 0.0f); glutWireTorus(0.3f, 1.0f, 12, 24); glPopMatrix(); glPushMatrix(); glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f); glRotatef(-55.0f, 1.0f, 0.0f, 0.0f); glutWireTorus(0.3f, 1.0f, 12, 24); glPopMatrix(); } //Draw to window window.MakeCurrent(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera.SetupViewMatrix(); glLoadMatrixf(camera.viewMatrix); glBindTexture(GL_TEXTURE_2D, pbufferTexture); //use the pbuffer as the texture wglBindTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB); //Draw simple rectangle glBegin(GL_TRIANGLE_STRIP); { glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); } glEnd(); //release the pbuffer for further rendering wglReleaseTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB); fpsCounter.Update(); //update frames per second counter glColor4f(1.0f, 1.0f, 0.0f, 1.0f); window.StartTextMode(); window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps()); //print the fps glColor4f(1.0f, 0.0f, 0.0f, 1.0f); window.Print(0, 48, "%dx Anisotropy", currentAnisotropy); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); window.Print(0, 68, "%s", useMipmapFilter ? "LINEAR_MIPMAP_LINEAR filtering" : "LINEAR filtering"); window.EndTextMode(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); if(window.isKeyPressed(VK_F1)) { window.SaveScreenshot(); window.SetKeyReleased(VK_F1); } window.SwapBuffers(); //swap buffers //check for any opengl errors window.CheckGLError(); //quit if necessary if(window.isKeyPressed(VK_ESCAPE)) PostQuitMessage(0); }
static void draw_water_grid(float texture_max_u, float texture_max_v) { int i, j; float x, y, dx, dy; float du, dv; const struct rgba *color = settings.static_settings->water_color; const int use_pbuffer = settings.static_settings->use_pbuffer; const int use_pbuffer_render_texture = settings.static_settings->use_pbuffer_render_texture; glPushAttrib(GL_ALL_ATTRIB_BITS); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, backg_texture_id); /* glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */ if (use_pbuffer && use_pbuffer_render_texture) { #ifdef WIN32 wglBindTexImageARB(pbuffer, WGL_FRONT_LEFT_ARB); #else assert(0); #endif } glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, gl_texture_id(env_texture_id)); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glShadeModel(GL_FLAT); glDisable(GL_CULL_FACE); glColor4f(color->r, color->g, color->b, color->a); dx = 2.f*WATER_QUAD_RADIUS/(2*WATER_GRID_SIZE); dy = 2.f*WATER_QUAD_RADIUS/(2*WATER_GRID_SIZE); du = texture_max_u; dv = texture_max_v; x = -WATER_QUAD_RADIUS; for (i = 0; i < 2*WATER_GRID_SIZE - 1; i++) { y = -WATER_QUAD_RADIUS; glBegin(GL_TRIANGLE_STRIP); for (j = 0; j < 2*WATER_GRID_SIZE - 1; j++) { glMultiTexCoord2fARB(GL_TEXTURE0_ARB, du*backg_uv_map[i][j].x, dv*backg_uv_map[i][j].y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, env_uv_map[i][j].x, env_uv_map[i][j].y); glVertex2f(x, y); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, du*backg_uv_map[i + 1][j].x, dv*backg_uv_map[i + 1][j].y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, env_uv_map[i + 1][j].x, env_uv_map[i + 1][j].y); glVertex2f(x + dx, y); y += dy; } glEnd(); x += dx; } if (use_pbuffer && use_pbuffer_render_texture) { #ifdef WIN32 wglReleaseTexImageARB(pbuffer, WGL_FRONT_LEFT_ARB); #else assert(0); #endif } glPopAttrib(); }
void ParticleShaderVoronoi::drawPost() { // Get the viewport dimensions GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); if ((pbufferOne->height != viewport[3]) || (pbufferOne->width != viewport[2])) { delete pbufferOne; setupBuffers(viewport[2], viewport[3]); } // Get the light position GLfloat lightpos[4]; glGetLightfv(GL_LIGHT0, GL_POSITION, lightpos); // Create storage for matrices GLfloat mm[16]; GLfloat pm[16]; // If we're not sharing contexts, need to copy state glGetFloatv(GL_MODELVIEW_MATRIX, mm); glGetFloatv(GL_PROJECTION_MATRIX, pm); // Switch to pbufferOne rendering context if (wglMakeCurrent(pbufferOne->hdc, pbufferOne->hglrc) == FALSE) pbufferOne->wglGetLastError(); // If we're not sharing contexts, need to update state if (pbufferOne->onecontext == false) { glMatrixMode(GL_PROJECTION); glLoadMatrixf(pm); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(mm); glEnable(GL_DEPTH_TEST); } else { // Turn off color writes, for better performance glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); } // Clear the depth texture glClear(GL_DEPTH_BUFFER_BIT); cgGLEnableProfile(vProfile); cgGLEnableProfile(fProfile); cgGLBindProgram(vProgram); bindCGParametersVertex(); cgGLBindProgram(fProgramZero); bindCGParametersFragmentZero(); // Draw into the buffer for the depth texture for (unsigned int i = 0; i < ps->size(); i++) drawParticle(i); // Turn back on color for eventual rendering if (pbufferOne->onecontext) { glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } cgGLDisableProfile(vProfile); cgGLDisableProfile(fProfile); // Switch to normal rendering context if (wglMakeCurrent(hdc, hglrc) == FALSE) pbufferOne->wglGetLastError(); // Setup CG cgGLEnableProfile(vProfile); cgGLEnableProfile(fProfile); cgGLBindProgram(vProgram); bindCGParametersVertex(); bindCGParametersFragmentOne(); cgGLBindProgram(fProgramOne); // Make the depth texture active glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB"); glActiveTextureARB(GL_TEXTURE0_ARB); // Bind the depth texture glEnable(GL_TEXTURE_RECTANGLE_NV); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glBindTexture(GL_TEXTURE_RECTANGLE_NV, depth_texture); // Bind pbufferOne as a depth texture wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB"); if (wglBindTexImageARB(pbufferOne->hpbuffer, WGL_DEPTH_COMPONENT_NV) == FALSE) pbufferOne->wglGetLastError(); cgGLEnableTextureParameter(firstPassDepth); glActiveTextureARB(GL_TEXTURE1_ARB); // Set parameters cgGLSetParameter1f(depthRange, GLfloat(abs(10.0 - 0.5))); cgGLSetParameter4fv(lightPositionEC, lightpos); cgGLSetParameter1f(toleranceScaleFactor, GLfloat(toleranceScale)); cgGLSetStateMatrixParameter(viewMatrix, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY); glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Draw the particles to the screen for (unsigned int i = 0; i < ps->size(); i++) { drawSecondPass(i); } cgGLDisableTextureParameter(firstPassDepth); glDisable(GL_TEXTURE_RECTANGLE_NV); // Release the depth texture wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB"); if (wglReleaseTexImageARB(pbufferOne->hpbuffer, WGL_DEPTH_COMPONENT_NV) == false) pbufferOne->wglGetLastError(); cgGLDisableProfile(vProfile); cgGLDisableProfile(fProfile); }