Hey, I'm working on a simple lua module where I try to grab the pixel data from an ITexture. This is what I'm doing to get the texture.
[CODE]
Lua()->CheckType(1, GLua::TYPE_TEXTURE);
ITexture* tex = (ITexture *)Lua()->GetUserData(1);
[/CODE]
Any help would be appreciated. :)
I believe there is already a module for this :l
I checked, if you know what it is feel free to post it...
I said I checked, if it were that obvious I wouldn't have bothered making a thread...
In his code to render the image to a texture, hes using vgui::ISurface to draw the texture according to the image buffer.
[CODE]
Lua()->CheckType( 1, TYPE_IMAGE );
Lua()->CheckType( 2, GLua::TYPE_NUMBER );
CImage* image = reinterpret_cast<CImage*>( Lua()->GetUserData( 1 ) );
int textureId = Lua()->GetInteger( 2 );
// commit
g_pSurface->DrawSetTextureRGBA( textureId, image->GetBuffer(), image->GetWidth(), image->GetHeight(), false, true );
[/CODE]
And for getting pixels hes retrieving them directly from the image, not a texture.
I on the other hand am trying to access the pixels. :\
I'm not so sure you are supposed to set the pixels outside of a regenerator, or on a texture that's not set to procedural.
What about a render target?
There might be something in IVTFTexture, but it doesn't appear that there's a way to do this with ITexture.
[url=http://developer.valvesoftware.com/wiki/ITexture]ITexture[/url]
I'm not sure if what I'm looking at is wrong, or the source you gave was outdated. Here is what I found in public/materialsystem/itexture.h
[CODE]
abstract_class ITexture
{
public:
// Various texture polling methods
virtual const char *GetName( void ) const = 0;
virtual int GetMappingWidth() const = 0;
virtual int GetMappingHeight() const = 0;
virtual int GetActualWidth() const = 0;
virtual int GetActualHeight() const = 0;
virtual int GetNumAnimationFrames() const = 0;
virtual bool IsTranslucent() const = 0;
virtual bool IsMipmapped() const = 0;
virtual void GetLowResColorSample( float s, float t, float *color ) const = 0;
// Gets texture resource data of the specified type.
// Params:
// eDataType type of resource to retrieve.
// pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
// Returns:
// pointer to the resource data, or NULL
virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const = 0;
// Methods associated with reference count
virtual void IncrementReferenceCount( void ) = 0;
virtual void DecrementReferenceCount( void ) = 0;
inline void AddRef() { IncrementReferenceCount(); }
inline void Release() { DecrementReferenceCount(); }
// Used to modify the texture bits (procedural textures only)
virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) = 0;
// Reconstruct the texture bits in HW memory
// If rect is not specified, reconstruct all bits, otherwise just
// reconstruct a subrect.
virtual void Download( Rect_t *pRect = 0 ) = 0;
// Uses for stats. . .get the approximate size of the texture in it's current format.
virtual int GetApproximateVidMemBytes( void ) const = 0;
// Returns true if the texture data couldn't be loaded.
virtual bool IsError() const = 0;
// NOTE: Stuff after this is added after shipping HL2.
// For volume textures
virtual bool IsVolumeTexture() const = 0;
virtual int GetMappingDepth() const = 0;
virtual int GetActualDepth() const = 0;
virtual ImageFormat GetImageFormat() const = 0;
virtual NormalDecodeMode_t GetNormalDecodeMode() const = 0;
// Various information about the texture
virtual bool IsRenderTarget() const = 0;
virtual bool IsCubeMap() const = 0;
virtual bool IsNormalMap() const = 0;
virtual bool IsProcedural() const = 0;
virtual void DeleteIfUnreferenced() = 0;
#if defined( _X360 )
virtual bool ClearTexture( int r, int g, int b, int a ) = 0;
virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture ) = 0;
#endif
// swap everything except the name with another texture
virtual void SwapContents( ITexture *pOther ) = 0;
// Retrieve the vtf flags mask
virtual unsigned int GetFlags( void ) const = 0;
// Force LOD override (automatically downloads the texture)
virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) = 0;
};
[/CODE]
[CODE]
// Gets texture resource data of the specified type.
// Params:
// eDataType type of resource to retrieve.
// pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
// Returns:
// pointer to the resource data, or NULL
virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const = 0;
[/CODE]
Could that possibly be what I'm looking for? And I took another look at gm_image and saw...
[CODE]
// allocate a new buffer
unsigned long imageSize = m_Width * m_Height * 4;
m_pBits = new unsigned char[ imageSize ];
// read
IMatRenderContext* context = materialsystem->GetRenderContext();
context->ReadPixels( x, y, width, height, m_pBits, IMAGE_FORMAT_RGBA8888 );
[/CODE]
Sorry, you need to Log In to post a reply to this thread.