Code covered by the BSD License  

Highlights from
OpenGL .NET Examples

image thumbnail
from OpenGL .NET Examples by Dirk-Jan Kroon
Matlab OpenGL .NET code and examples for R2009a and above

I=texture2matlab(TextureID,Width,Height)
function I=texture2matlab(TextureID,Width,Height)
% This function texture2matlab reads a RGBA UINT8 texture in the OpenGL video memory 
% to a Matlab variable
%
% I=texture2matlab(TextureID,Width,Height)
% 
% inputs,
%	TextureID : The opengl (int) id of a RGBA texture
% 	Width, Height: The width an height of the texture
%
% outputs,
%   I: The RGB Matlab image (double)
%
% example,
%
% figure, imshow(texture2matlab(textureid,512,512));
%
% Function is written by D.Kroon University of Twente (April 2009)

% Allow to use GL functions without prefixing with Tao.Opengl.
import Tao.OpenGl.*

% Get the texture data
texturedata = NET.createArray('System.Byte',Width * Height* 4);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, TextureID);
Gl.glGetTexImage(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, texturedata );
Gl.glDisable(Gl.GL_TEXTURE_2D);

% Convert texture data to Matlab image
I=reshape(double(texturedata),[4 Width Height]);
I=permute(I,[3 2 1]);
I=I(:,:,1:3)/255;
    

Contact us at files@mathworks.com