Beispiel #1
0
void CreateShadowTexture (void)
{
	GLint	i;

if (!bHaveShadowBuf) {
	memset (&shadowBuf, 0, sizeof (shadowBuf));
	shadowBuf.bmProps.w = STB_SIZE_X;
	shadowBuf.bmProps.h = STB_SIZE_Y;
	shadowBuf.bmProps.flags = (char) BM_FLAG_TGA;
	shadowBuf.bmTexBuf = shadowTexBuf;
	OglLoadBmTextureM (&shadowBuf, 0, -1, 0, NULL);
	bHaveShadowBuf = 1;
	}
#if 1
//glStencilFunc (GL_EQUAL, 0, ~0);
//RenderShadowQuad (1);
#	if 0
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, grdCurCanv->cvBitmap.bmProps.h - 128, 128, 128, 0);
#	else
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, 0,
						grdCurCanv->cvBitmap.bmProps.w, 
						grdCurCanv->cvBitmap.bmProps.h, 0);
#	endif
#else
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, 128, 128);
#endif
i = glGetError ();
}
Beispiel #2
0
void CreateShadowTexture (void)
{
	GLint	i;

if (!bHaveShadowBuf) {
	memset (&shadowBuf, 0, sizeof (shadowBuf));
	shadowBuf.SetWidth (STB_SIZE_X);
	shadowBuf.SetHeight (STB_SIZE_Y);
	shadowBuf.SetFlags ((char) BM_FLAG_TGA);
	shadowBuf.SetBuffer (shadowTexBuf);
	shadowBuf.SetTranspType (-1);
	shadowBuf.PrepareTexture (0, 0, NULL);
	bHaveShadowBuf = 1;
	}
#if 1
//glStencilFunc (GL_EQUAL, 0, ~0);
//RenderShadowQuad (1);
#	if 0
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, CCanvas::Current ()->Height () - 128, 128, 128, 0);
#	else
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, 0,
						CCanvas::Current ()->Width (), 
						CCanvas::Current ()->Height (), 0);
#	endif
#else
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, 128, 128);
#endif
i = glGetError ();
}
Beispiel #3
0
/*!
    Copies the pbuffer contents into the texture specified with \a
    texture_id.

    The texture must be of the same size and format as the pbuffer.

    Example:

    \snippet doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp 1

    An alternative on Windows and Mac OS X systems that support the
    \c render_texture extension is to use bindToDynamicTexture() to
    get dynamic updates of the texture.

    \sa generateDynamicTexture(), bindToDynamicTexture()
*/
void QGLPixelBuffer::updateDynamicTexture(GLuint texture_id) const
{
    Q_D(const QGLPixelBuffer);
    if (d->invalid)
        return;
    glBindTexture(GL_TEXTURE_2D, texture_id);
#ifndef QT_OPENGL_ES
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, d->req_size.width(), d->req_size.height(), 0);
#else
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, d->req_size.width(), d->req_size.height(), 0);
#endif
}
void CanvasLayerWebKitThread::updateTextureContentsIfNeeded()
{
    if (!m_needsDisplay || !m_device)
        return;

    m_needsDisplay = false;
    m_device->makeRenderTargetCurrent();

    GLint previousTexture;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTexture);

    if (!m_texID) {
        glGenTextures(1, &m_texID);
        glBindTexture(GL_TEXTURE_2D, m_texID);
        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);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_device->width(), m_device->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

        createFrontBufferLock();
    }

    pthread_mutex_lock(m_frontBufferLock);
    glBindTexture(GL_TEXTURE_2D, m_texID);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_device->width(), m_device->height(), 0);
    glBindTexture(GL_TEXTURE_2D, previousTexture);
    pthread_mutex_unlock(m_frontBufferLock);
}
        void FrostAdapter::DrawEffect(_In_ IEffect * effect)
        {
            if (!effect)
            {
                m_Core->GetLogger()->LogMessage(VSLog_ModError, VOODOO_FROST_NAME, VSTR("Unable to draw null shader."));
                return;
            }

            ITechniqueRef tech = effect->GetDefaultTechnique();

            if (!tech)
            {
                m_Core->GetLogger()->LogMessage
                (
                    VSLog_ModError, VOODOO_FROST_NAME,
                    Format("No default technique given for shader %1%.") << effect 
                );
                return;
            }

            glMatrixMode(GL_PROJECTION);
            glPushMatrix();
            glLoadIdentity();
            glOrtho(0, 250.0, 250.0, 0, -1, 1);
            glMatrixMode(GL_MODELVIEW);
            glPushMatrix();
            glLoadIdentity();

            this->SetEffect(effect);
            uint32_t passes = tech->GetPassCount();

            for (size_t curpass = 0; curpass < passes; ++curpass)
            {
                IPassRef pass = tech->GetPass(curpass);

                this->SetPass(pass.get());
                //this->DrawGeometry(0, 0, nullptr, VF_None);
                this->ResetPass();

                ITextureRef target = pass->GetTarget(0);

                if (target)
                {
                    Variant targetVar = CreateVariant();
                    if (SUCCEEDED(target->GetProperty(PropIds::OpenGLTexture, &targetVar)) && targetVar.Type == UT_UInt32)
                    {
                        GLuint passtarget = (GLuint) targetVar.VUInt32.X;

                        glBindTexture(GL_TEXTURE_2D, passtarget);
                        glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 250, 250, 0);
                    }
                }
            }
            this->ResetEffect();

            glMatrixMode(GL_PROJECTION);
            glPopMatrix();
            glMatrixMode(GL_MODELVIEW);
            glPopMatrix();
        }
//--------------------------------------------------------
void CShaderNode::draw()
{
	CC_NODE_DRAW_SETUP();  

	//传递uniform变量  
	CCGLProgram* shader = getShaderProgram();  
	shader->setUniformLocationWith2f(m_unUniformResolution, m_tagResolutionPos.x, m_tagResolutionPos.y);
	shader->setUniformLocationWith1i(m_unUniformTex0, 0); 
	glUniform1f(m_unUniformTime, m_fTime);

	//获取attribute变量  
	CCSize size = this->getContentSize();  
	float w = size.width;  
	float h = size.height;  

	ccGLBindTexture2D(m_pTexture);								//绑定纹理到槽位  
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w, h, 0); //截取屏幕数据到纹理  
	glEnableVertexAttribArray(m_unAttributePosition); 

	//传递attribute变量  
	GLfloat vertices[12] = {  
		0, 0, //左下0
		w, 0, //右下1
		w, h, //右上2
		0, 0, //左下0
		0, h, //左上3
		w, h, //右上2
	};  
	glVertexAttribPointer(m_unAttributePosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);  
	glVertexAttrib4fv(m_unAttributeColor, m_fColor);  
	//绘制  
	glDrawArrays(GL_TRIANGLES, 0, 6);  
}
Beispiel #7
0
void CWater::CreateRefractionDepthTexture(int textureSize)
{
	// To create the refraction and depth textures we do the same thing
	// we did for the reflection texture, except we don't need to turn
	// the world upside down.  We want to find the depth of the water,
	// not the depth of the sky and above water terrain.
	
    glViewport(0,0, textureSize, textureSize);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

	// If the camera is above water, render the data below the water
	double plane[4] = {0.0, -1.0, 0.0, m_fWaterCPos[1]}; 
	glEnable(GL_CLIP_PLANE0);
	glClipPlane(GL_CLIP_PLANE0, plane);
	//RenderWorld(true); I need to add some extra code to specify the objects that are under water
	glDisable(GL_CLIP_PLANE0);

	g_render.PopMatrix();
	glFlush();

    // Bind the current scene to our refraction texture
    glBindTexture(GL_TEXTURE_2D, m_waterTexture[WATER_REFRACTION_ID]);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);

    // Bind the current scene to our depth texture
    glBindTexture(GL_TEXTURE_2D, m_waterTexture[WATER_DEPTH_ID]);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);

}
Beispiel #8
0
GLint IMaterial::GetScreenTexture()
{
    glBindTexture(GL_TEXTURE_2D, m_gMainTexFrameBuffer);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_fViewportWidth, m_fViewportHeight, 0);
    
    return m_gMainTexFrameBuffer;
}
Beispiel #9
0
GPU::Texture2D GPU::Texture2D::Clone() const
{
    glPushAttrib( GL_TEXTURE_BIT );

    GPU::Texture2D newTex;
    newTex.Create();
    newTex.m_Width = Width();
    newTex.m_Height = Height();

    if( m_Id )
    {
        GPU::FrameBuffer fbuffer( Width(), Height() );
        fbuffer.Attach( GL_COLOR_ATTACHMENT0_EXT, this );
        fbuffer.Bind();

        newTex.Bind();
        glCopyTexImage2D( GL_TEXTURE_2D, 0, InternalFormat(), 0, 0, Width(), Height(), 0 );
        newTex.Unbind();

        fbuffer.Unbind();
    }

    glPopAttrib();

    return newTex;
}
Beispiel #10
0
GLuint CopyDepthTexture (void)
{
	GLenum nError = glGetError ();

#if DBG
if (nError)
	nError = nError;
#endif
ogl.SelectTMU (GL_TEXTURE1);
glEnable (GL_TEXTURE_2D);
if (!ogl.m_states.hDepthBuffer)
	ogl.m_states.bHaveDepthBuffer = 0;
if (ogl.m_states.hDepthBuffer || (ogl.m_states.hDepthBuffer = ogl.CreateDepthTexture (-1, 0))) {
	glBindTexture (GL_TEXTURE_2D, ogl.m_states.hDepthBuffer);
	if (!ogl.m_states.bHaveDepthBuffer) {
#if 0
		glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, screen.Width (), screen.Height (), 0);
#else
		glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen.Width (), screen.Height ());
#endif
		if ((nError = glGetError ())) {
			glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen.Width (), screen.Height ());
			if ((nError = glGetError ())) {
				DestroyGlareDepthTexture ();
				return ogl.m_states.hDepthBuffer = 0;
				}
			}
		ogl.m_states.bHaveDepthBuffer = 1;
		gameData.render.nStateChanges++;
		}
	}
return ogl.m_states.hDepthBuffer;
}
Beispiel #11
0
GLuint renderTOrenderBuffer(){

	glBindFramebuffer(GL_FRAMEBUFFER,fboID);
	//glBindRenderbuffer(GL_RENDERBUFFER,rboID);

	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glBindTexture(GL_TEXTURE_2D, RTtexture);

	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_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	//把坐标(0,0)到(gWidth,gHeight)的屏幕像素拷贝到纹理
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, gWidth, gHeight, 0);

//	char a[4] = { 0 };
//	char *p = a;
//	glReadPixels(110, 110, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, p);
//	LOGI("...........1= %d", p[0]);
//	LOGI("...........2= %d", p[1]);
//	LOGI("...........3= %d", p[2]);
//	LOGI("...........4= %d", p[3]);

	glBindFramebuffer(GL_FRAMEBUFFER,0);
}
void LLRenderTarget::flush(bool fetch_depth)
{
	gGL.flush();
	if (!mFBO)
	{
		gGL.getTexUnit(0)->bind(this);
		glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, 0, 0, 0, 0, mResX, mResY);

		if (fetch_depth)
		{
			if (!mDepth)
			{
				allocateDepth();
			}

			gGL.getTexUnit(0)->bind(this);
			glCopyTexImage2D(LLTexUnit::getInternalType(mUsage), 0, GL_DEPTH24_STENCIL8, 0, 0, mResX, mResY, 0);
		}

		gGL.getTexUnit(0)->disable();
	}
	else
	{
		stop_glerror();

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
					stop_glerror();
				}
			}
Beispiel #13
0
static void do_bloom(CTexture* t)
{
	glBindTexture(GL_TEXTURE_2D, 0);
	glViewport(0, 0, t->_size, t->_size);
	glCullFace(GL_BACK);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(true);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_FOG);
	glFogf(GL_FOG_START, RenderFogDistance() / 2);
	glFogf(GL_FOG_END, RenderFogDistance());
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);
	EntityRender();
	CarRender();
	LightRender();
	glBindTexture(GL_TEXTURE_2D, t->_glid);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, t->_size, t->_size, 0);
}
void GL1TextureProvider::copy_image_from(
    int x,
    int y,
    int width,
    int height,
    int level,
    TextureFormat texture_format,
    GraphicContextProvider *gc)
{
    throw_if_disposed();
    OpenGL::set_active(static_cast<GL1GraphicContextProvider*>(gc));
    GL1TextureStateTracker state_tracker(texture_type, handle);

    GLint gl_internal_format;
    GLenum gl_pixel_format;
    to_opengl_textureformat(texture_format, gl_internal_format, gl_pixel_format);

    glCopyTexImage2D(
        GL_TEXTURE_2D,
        level,
        gl_internal_format,
        x, y,
        width, height,
        0);
}
Beispiel #15
0
void DoBlur(unsigned int uiSrcTex, unsigned int uiTargetTex, int srcTexWidth, int srcTexHeight, int destTexWidth, int destTexHeight, float xofs, float yofs)
{
	cgGLBindProgram(g_cgVP_GlowBlur);
	cgGLBindProgram(g_cgFP_GlowBlur);

	pglActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE2_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	pglActiveTextureARB(GL_TEXTURE3_ARB);
	glEnable(GL_TEXTURE_RECTANGLE_NV);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiSrcTex);

	cgGLSetParameter1f(g_cgpVP1_XOffset, xofs);
	cgGLSetParameter1f(g_cgpVP1_YOffset, yofs);

	glViewport(0, 0, destTexWidth, destTexHeight);

	DrawQuad(srcTexWidth, srcTexHeight);

	glBindTexture(GL_TEXTURE_RECTANGLE_NV, uiTargetTex);
	glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, destTexWidth, destTexHeight, 0);
}
Beispiel #16
0
void 
HaloRefImage::copy_to_scratch()
{
   check_resize();
   assert(_scratch_tex &&
          _scratch_tex->image().dims() == Point2i(VIEW::cur_size()));

   glPushAttrib(GL_ENABLE_BIT);

   // Specify texture
   _scratch_tex->apply_texture();   // GL_ENABLE_BIT

   glReadBuffer(GL_BACK);

   // Copies the frame buffer into a texture in gpu texture memory.
   glCopyTexImage2D(
      GL_TEXTURE_2D,  // The target to which the image data will be changed.
      0,              // Level of detail, 0 is base detail
      GL_RGBA,        // internal format
      0,              // x-coord of lower left corner of the window
      0,              // y-coord of lower left corner of the window
      _width,         // texture width
      _height,        // texture height
      0);             // border size, must be 0 or 1

   glPopAttrib();
}
Beispiel #17
0
void SimpleRender::draw(GLuint program, ESMatrix* pMat, ESMatrix* vMat, GLsizei SCREEN_WIDTH, GLsizei SCREEN_HEIGHT) {
	GLuint framebuffer = create_empty_texture();
	GLuint water_texture = create_water_texture();

	glClear (GL_COLOR_BUFFER_BIT);

	//Draw fuild here
	glBindTexture(GL_TEXTURE_2D, water_texture);
	glBlendFunc(GL_ONE, GL_ONE);//Additive rendering
//	for(std::list<fluid_c>::const_iterator i = fluid.begin(); i != fluid.end(); i++) i->draw();

	//Copy the screen into a texture
	glBindTexture(GL_TEXTURE_2D, framebuffer);
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);

	//Draw a transparent black rectangle over the whole screen
	//Instead of just clearing the screen we now leave the original (non-metaball) image slightly visible to produce glow
	glDisable (GL_TEXTURE_2D);
	glColor4f(0.0, 0.0, 0.0, 0.7);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable (GL_TEXTURE_2D);

	//Redraw the copied screen and produce metaballs
	//Metaballs are produced simply by discarding pixels that don't have enough alpha
	glEnable (GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.85); //Discard treshold
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glBlendFunc(GL_SRC_ALPHA, GL_ZERO);//Discard current screen pixels of pixels that are redrawn
	draw_fullscreen_rectangle();
	glDisable (GL_ALPHA_TEST);
}
Beispiel #18
0
void DrawRedarToTexture()
{
	DrawBlackBack(256);


	//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA   );
	glEnable(GL_BLEND);
	//glPrintRedar(0,0,-1,tmpredarRenge);
	for(int i=1;i<maxUnits;i++)
	{
		if(UDfighers[i].UDlife>0)
		if(UDfighers[i].UDwinl<(tmpredarRenge*tmpredarRenge))
		{
			float vx,vy,vz;
			//Vredar=MView.Matrix() * UDfighers[i].UDMplane.RefPos() + MView.RefPos();
			//Vredar=UDfighers[i].UDMplane.RefPos()-MFighter.RefPos();
			vx=(float)(UDfighers[i].UDMplane.RefPos()(0)-UDfighers[0].UDMplane.RefPos()(0));
			vy=(float)(UDfighers[i].UDMplane.RefPos()(1)-UDfighers[0].UDMplane.RefPos()(1));
			vz=(float)(UDfighers[i].UDMplane.RefPos()(2)-UDfighers[0].UDMplane.RefPos()(2));

			if(UDfighers[i].UDlockselect)
				{
					if(lockflash>15)
						glPrintRedar(vx,vz,UDfighers[i].UDflag,tmpredarRenge);
				}
				else
					glPrintRedar(vx,vz,UDfighers[i].UDflag,tmpredarRenge);
		}
	
	}
	glBindTexture(GL_TEXTURE_2D,RedarTexture);
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 256, 256, 0);
}
Beispiel #19
0
void texture::copyScreen(const vec2i& position, vec2u size)
{
    bind();
    if(!size.x) size.x = _size.x;
    if(!size.y) size.y = _size.y;
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, position.x, position.y, size.x, size.y, 0);
    _size = size;
}
Beispiel #20
0
void GLTexture::EndRenderTarget(int w, int h)
{
  glActiveTexture(GL_TEXTURE0);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, GetGLHandle());
  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0,0, width,height, 0);
  glViewport(0,0, w,h);
}
Beispiel #21
0
void 
HaloRefImage::copy_to_tex_aux()
{
   check_resize();
   assert(_texture && _texture->image().dims() == Point2i(VIEW::cur_size()));

   glPushAttrib(GL_ENABLE_BIT);

   // Specify texture
   _texture->apply_texture();   // GL_ENABLE_BIT

   if (use_fbos) {
      //copy contents of the frame buffer to output texture
      glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);

      // Copies the frame buffer into a texture in gpu texture memory.
      glCopyTexImage2D(
         GL_TEXTURE_2D,  // The target to which the image data will be changed.
         0,              // Level of detail, 0 is base detail
         GL_RGBA,        // internal format
         0,              // x-coord of lower left corner of the window
         0,              // y-coord of lower left corner of the window
         _width,         // texture width
         _height,        // texture height
         0);             // border size, must be 0 or 1

      glBindFramebuffer(GL_FRAMEBUFFER, 0);

   } else {
      //copy contents of the aux0 buffer to output texture
      glReadBuffer(GL_AUX0);

      // Copies the frame buffer into a texture in gpu texture memory.
      glCopyTexImage2D(
         GL_TEXTURE_2D,  // The target to which the image data will be changed.
         0,              // Level of detail, 0 is base detail
         GL_RGBA,        // internal format
         0,              // x-coord of lower left corner of the window
         0,              // y-coord of lower left corner of the window
         _width,         // texture width
         _height,        // texture height
         0);             // border size, must be 0 or 1
   }

   glPopAttrib();
}
Beispiel #22
0
static void load_texture_from_screen(texture_asset* texture, int32 bottom_y, int32 x, int32 y, int32 width, int32 height) {
	texture->size = { width, height };
	bind_texture(texture);
	set_texture_parameters(texture);
	CHECK_GL_ERROR();
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, bottom_y - y - height, width, height, 0);
	CHECK_GL_ERROR();
}
Beispiel #23
0
void GL::Texture::copyImage2D(TextureTarget target, GLint level, InternalFormat internalFormat,
                              GLint x, GLint y,
                              GLsizei width, GLsizei height, GLint border)
{
    glCopyTexImage2D(GLenum(target), level, GLint(internalFormat),
                     x, y,
                     width, height, border);
}
Beispiel #24
0
GDECLSPEC GLES2D_Texture *GLES2D_CreateTextureFromBuffer()
{
	GLES2D_Texture *tex;
	tex = (GLES2D_Texture *) malloc( sizeof( GLES2D_Texture ) );

	GLES2D_Rect *src;
	src = (GLES2D_Rect *) malloc( sizeof( GLES2D_Rect ) );

	GLES2D_Rect *dst;
	dst = (GLES2D_Rect *) malloc( sizeof( GLES2D_Rect ) );

	tex->src = src;
	tex->dst = dst;

	int w = GLES2D_p2( 800 );
	int h = GLES2D_p2( 480 );
	tex->texw = (GLfloat) 800 / w;
	tex->texh = (GLfloat) 480 / h;
	tex->format = RGB565;
	tex->src->w = 800;
	tex->src->h = 480;
	tex->src->x = 0;
	tex->src->y = 0;
	tex->dst->w = 800;
	tex->dst->h = 480;
	tex->dst->x = 0;
	tex->dst->y = 0;
	tex->image_w = 800;
	tex->image_h = 480;
	tex->isbuffer = 1;
	tex->filtering = 0;
	tex->centered = 0;
	tex->rotation = 0;
	tex->color[0] = 1.0f;
	tex->color[1] = 1.0f;
	tex->color[2] = 1.0f;
	tex->color[3] = 1.0f;
	tex->colorAlpha[0] = 1.0f;
	tex->colorAlpha[1] = 1.0f;
	tex->colorAlpha[2] = 1.0f;
	tex->collision_set = 0;
	tex->flipX = 0;
	tex->flipY = 0;

	glGenTextures( 1, &tex->texID );
 
	// Bind the texture object
	glBindTexture( GL_TEXTURE_2D, tex->texID );
 
	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_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

	glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, w, h, 0 );

	return tex;
}
///----------------------------------------------------------------------------
///Creates the shadow map texture based on light's point of view.
///----------------------------------------------------------------------------
void GLApp::CreateShadowMap(GLfloat angle)
{
	//clear the depth and color buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//disable lighting and textures
	glShadeModel(GL_FLAT);
	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);

	//render from light's point of view
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	{
		glLoadMatrixd(m_LightProjectionMatrix);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		{
			//disable writing on frame-buffer color components
			glColorMask(0,0,0,0);

			//TODO comment this line... avoid z-fighting
			glEnable(GL_POLYGON_OFFSET_FILL);
			glPolygonOffset(1.0, 4.0);
			
			glLoadMatrixd(m_LightViewMatrix);
			m_Geometry.Draw(angle);
			
			glDisable(GL_POLYGON_OFFSET_FILL);

			//restore color component writing
			glColorMask(1,1,1,1);
		}
		glPopMatrix();
	
		glMatrixMode(GL_PROJECTION);
	}
	glPopMatrix();

	//subsequent calls to glBindTexture activates the texture object
	glBindTexture(GL_TEXTURE_2D, m_Geometry.GetShadowTexObj());

	//Copy the depth buffer into the depth map texture object
	glCopyTexImage2D(GL_TEXTURE_2D,			//target, must be GL_TEXTURE_2D
					 0,						//LOD number, 0 is the base
					 GL_DEPTH_COMPONENT,	//Internal format for texture data
					 0,						//The window coordinates of the lower-left corner
					 0,						//of the rectangular region of pixels to be copied
					 m_Width,				//width of texture image (must be power of 2)
					 m_Height,				//height of texture image (must be power of 2)
					 0);					//border width

	//restore render states
	glCullFace(GL_BACK);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
}
Beispiel #26
0
void Texture::BackBufferToTex(int frame){
	if(flags&128){
		glBindTexture (GL_TEXTURE_CUBE_MAP,texture);
		switch (cube_face){
		case 0:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		case 1:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		case 2:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		case 3:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		case 4:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		case 5:
			glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA,0,Global::height-height,width,height,0);
			break;
		}
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
	}else{
		glBindTexture (GL_TEXTURE_2D,texture);
		glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,Global::height-height,width,height,0);
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
	}
}
Beispiel #27
0
void CGLfbo::CopyTexture(const uint32_t target) const
{
	glBindTexture(GL_TEXTURE_2D, target);
	checkGLError();
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 0, 0, mWidth, mHeight, 0);
	checkGLError();
	glBindTexture(GL_TEXTURE_2D, 0);
	checkGLError();
}
Beispiel #28
0
void opengl_start_transition(bool direction)
{
	transition = true;
	transition_direction = direction;
	transition_w = screen_size_w;
	glBindTexture(GL_TEXTURE_2D, screenshot_tex);
	
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, nextPowerOfTwo(screen_size_w), nextPowerOfTwo(screen_size_h), 0);
}
Beispiel #29
0
static int
create_fbo(void)
{
	GLuint tex, copied_tex, fb;
	GLenum status;
	int i, dim;
	int draw_w = TEX_WIDTH / 2, draw_h = TEX_HEIGHT / 2;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
			     dim, dim,
			     0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	assert(glGetError() == 0);

	/* Draw into the second level. */
	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  1);
	assert(glGetError() == 0);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "FBO incomplete\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	glViewport(0, 0, draw_w, draw_h);
	piglit_ortho_projection(draw_w, draw_h, GL_FALSE);

	glColor4fv(red);
	piglit_draw_rect(0, 0, draw_w / 2, draw_h / 2);
	glColor4fv(green);
	piglit_draw_rect(draw_w / 2, 0, draw_w, draw_h / 2);
	glColor4fv(blue);
	piglit_draw_rect(0, draw_h / 2, draw_w/2, draw_h);
	glColor4fv(white);
	piglit_draw_rect(draw_w / 2, draw_h / 2, draw_w, draw_h);

	glGenTextures(1, &copied_tex);
	glBindTexture(GL_TEXTURE_2D, copied_tex);
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, draw_w, draw_h, 0);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);
	glDeleteTextures(1, &tex);

	return copied_tex;
}
Beispiel #30
0
void Texture::copyImage2D( GLint x, GLint y, GLsizei width, GLsizei height )
{
    KVS_ASSERT( m_target == GL_TEXTURE_2D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    const GLint border = 0; // border width (0 or 1)
    KVS_GL_CALL( glCopyTexImage2D( m_target, level, m_internal_format, x, y, width, height, border ) );
}