Code covered by the BSD License  

Highlights from
Matlab Offscreen Rendering Toolbox

3.0

3.0 | 2 ratings Rate this file 15 Downloads (last 30 days) File Size: 1.82 MB File ID: #25071
image thumbnail

Matlab Offscreen Rendering Toolbox

by Tianli Yu

 

19 Aug 2009 (Updated 30 Dec 2010)

Project 3D mesh onto image using off screen OpenGL rendering, determine face color, visibilty, etc.

| Watch this File

File Information
Description

This toolbox provides support to use OpenGL's rendering capability to project 3D triangular meshes onto an image plane. This has a few applications including extract the color of each face on the mesh given an observed image, determine the shadow area on the mesh given a light source direction and rendering a mesh.

Directly using OpenGL calls has the advantage of using more advanced graphics hardware capabilities, which results in faster rendering, and better control of anti-alliasing and other GL options.

This toolbox is used heavily to for the research of reflectance and illumination modeling published in Eurographics Symposium on Rendering 2006 and Siggraph 2007 Technical Sketch

1. Tianli Yu, Hongcheng Wang, Narendra Ahuja, Wei-Chao Chen, Sparse Lumigraph Relight by Illumination and Reflectance Estimation from Multi-View Images, Eurographics Symposium on Rendering (EGSR), 2006.
2.Tianli Yu, Hongcheng Wang, Narendra Ahuja, Wei-Chao Chen, Sparse Lumigraph Relight by Illumination and Reflectance Estimation from Multi-View Images, Technical Sketch, SIGGRAPH, 2006.

watch a youtube video of the result at:
http://tianliresearch.blogspot.com/

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (14)
19 Aug 2009 Luigi Giaccari

Warning: MEX could not find the library "glut"
         specified with -l option on the path specified
         with the -L option.
BatchFaceColorGradImpl.cpp
OffscreenGL.h(12) : fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory
 
  C:\PROGRA~1\MATLAB\R2009A~1\BIN\MEX.PL: Error: Compile of 'BatchFaceColorGradImpl.cpp' failed.

Never used open GL, any help?

20 Aug 2009 Tianli Yu

The package are tested in mac, but it should also work in windows once you set the correct include and lib path. Unfortunately I don't have Windows version of matlab at hand to test it out.

For windows, you will need to download the GLUT and GLEW binaries:
GLUT: http://www.xmission.com/~nate/glut.html
GLEW: http://glew.sourceforge.net/

Extract both zip files, GLEW will extract to a set of bin/, include/, doc/, lib/ folders. You could copy glut.h into glew/include/GL, glut32.lib into glew/lib/, so that they share the same path. And copy glew32.dll and glut32.dll into the offscreen root folder.

Then you could use modify the path in CompileOffscreen.m to something like this:

GlewPath = '-I./glew/include -L./glew/lib -lGLEW';
GlutPath = '-lglut';

You should be able to compile it now. Let me know if you have further problems.

04 Sep 2009 Srimal Jayawardena

Ok so it works this way when I add

-lGLEW -lGL -lGLU

to the include path as follows

GlewPath = '-I/usr/include/GL -L /usr/lib/ -lGLEW -lGL -lGLU';

I've had this issue issue before as well and ended up replying to my own post :)
http://www.mathworks.com/matlabcentral/newsreader/view_original/677788

14 Dec 2009 joli woo

mex -I.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\include\GL L.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\lib -lGLEW -I.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\include\GL L.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\lib -lglut BatchFaceColorGradImpl.cpp
 
  C:\PROGRA~1\MATLAB\R2007A\BIN\MEX.PL: Error: 'and' not found.
 
??? Error using ==> mex at 206
Unable to complete successfully.

Error in ==> CompileOffscreen at 17
eval(['mex ' GlewPath ' ' GlutPath ' BatchFaceColorGradImpl.cpp']);

my glutpath is set to GlewPath = '-I.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\include\GL L.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\lib -lGLEW';
 GlutPath = '-I.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\include\GL L.\C:\Documents and Settings\Administrator\My Documents\MATLAB\Offscreen\glew\lib -lglut';

Is there anything wrong there?

04 Jan 2010 Tianli Yu

The spaces in your GlewPath & GlutPath are causing the issue. Try to use "C:\DOCUME~1" in the path.

01 Feb 2010 Malcolm Reynolds

I got this compiled on Snow Leopard 10.6.2 (had to change the #include to <GLUT/glut.h> to stop error messages) but now I'm having the following problem when running:

EDU>> OffScreenTest
camnum =
    27
2010-02-01 18:36:48.265 MATLAB[33555:3503] GLUT Warning: glutInit being called a second time.
2010-02-01 18:36:48.311 MATLAB[33555:60f] GLUT Warning: The following is a new check for GLUT 3.0; update your code.
2010-02-01 18:36:48.312 MATLAB[33555:60f] GLUT Fatal Error: redisplay needed for window 1, but no display callback.

I get this if I run matlab with -nodesktop, and after this it crashes to the command line. If I try from within the full matlab GUI, it just disappears silently when it crashes.

If you could provide any guidance it would be most appreciated, I am looking to do something similar in terms of render to off-screen FBOs calling out from matlab and so getting your code working would be a big help.

Cheers,

Malcolm

03 Feb 2010 Tianli Yu

I cannot reproduce the crash on leopard, and I don't have a snow leopard to test with. Judging from the error message, you could try add a dummy display callback, by calling

void glutDisplayFunc(void (*func)(void));

after glutCreateWindow in OffscreenGL's constructor.

see glut's spec for more details
http://www.opengl.org/resources/libraries/glut/spec3/node46.html#SECTION00081000000000000000

19 Apr 2010 Al

In a Windows machine, I located glew and glud in C:\ and my setting is:

GlewPath = '-IC:/glew/include -LC:/glew/lib -lglew32';
GlutPath = '-IC:/glew/include -LC:/glew/lib -lglut32';

It compiles successfully.

25 Apr 2010 Gayathri

The code compiles successfully after providing a couple of dlls in the same directory as the code. But MATLAB crashes while trying to execute the code with the sample data provided. Need a more stabilized version that is independent of the platform.

31 Dec 2010 Diederick

People interested in Using OpenGL from MATLAB should have a look at the PsychToolBox (PTB), a library with extensive abilities that is used predominantly by vision researchers to program up their stimuli in MATLAB and display them through OpenGL. It includes MoGL, a Matlab wrapper around just about all OpenGL functionality, although PTB it also contains higher level functions, e.g. for easy drawing of dots, or procedural creation of Gabor patches.

16 Jul 2011 Michael Hödlmoser  
10 Aug 2011 Cihan Ula?

It seems it does not work in x64 Win7.
For x86, I used the following conf. and it worked propoerly.
1. Download glut and glew and extract them under C:\ path. They should be located as C:\glew and C:\glut.
2.Use the following paths which are found in CompileOffscreen file, which is located in offscreen folder.

GlewPath = '-IC:/glew/include -LC:/glew/lib -lGLEW32';
-LC:/glew/lib -lglut32';
GlutPath = '-IC:/glut -LC:/glut -lglut32';

11 Aug 2011 Tianli Yu

Re: Cihan Ula
If you are using 64 bit version of matlab, you will need 64 bit version of glut and glew, glut32 and GLEW32 won't work in this case.

19 Oct 2011 Jason Heym

I can compile and run the MEX functions. However, the offscreen window is not dismissed. When I click to close the window, Matlab crashes hard.

My setup:

Windows 7 x64
ATI FirePro V8800
Matlab R2011b (x64)
Visual Studio 2010 express
Microsoft Windows SDK 7.1
Freeglut 2.6.0 (compiled to x64 library)
GLEW 1.7.0 (static / -DGLEW_STATIC)

Anyone with a similar configuration?

I used Freeglut because it seemed more recent and had a visual C project file compatible with VC Express 2010.

Please login to add a comment or rating.
Updates
06 Sep 2009

Add a link to a rendering result video to the description.

30 Dec 2010

Remove all the binary files as requested by the reviewer.

Tag Activity for this File
Tag Applied By Date/Time
triangular mesh Tianli Yu 19 Aug 2009 10:04:08
off screen Tianli Yu 19 Aug 2009 10:04:08
camera Tianli Yu 19 Aug 2009 10:04:08
rendering Tianli Yu 19 Aug 2009 10:04:08

Contact us at files@mathworks.com