Francisco R. Ortega, Ph.D.

  • Blogs
  • Publications
  • CV – Resume
  • Events
  • Workshop
  • Teaching
    • All Courses
    • Java Workshop
    • Prog. Competition
    • CGS 4854
    • COP 2210
  • Resources
    • LIbCinder
    • Resource List
    • Vendor Links

Category Archives: GPU

Lib Cinder Brief Introduction video

Posted on January 22, 2014 by iblues1976 Posted in C++, CG, GPU, LibCinder

Hi,

I uploaded a brief introduction showing how to create a Lib Cinder project in MAC OS X (should be similar for windows)

http://www.youtube.com/watch?v=mmIJuZ3z23A

I also have uploaded the project. It can be found here.

Computer Graphics: First Presentation

Posted on April 3, 2013 by iblues1976 Posted in CG, featured, GPU, HCI, The Human Compiler

It had been a while since I had taken a class. This has been fun. Our team consist of the smart, driven and 100% CS Holly and Karina, Amazing CS programmer Jose and myself.  Our professor too is really nice and knowledgeable Dr. Zeng.   It is always great to have the support of my Major Professors (Dr. Rishe and Dr. Barreto)

We had a great presentation and currently working to have a great project finished by the end of the term.

Here are some pictures of our first presentation.

Francisco Francisco2 francisco3 HollyJoseKarinaFrancisco Karina Karina2

OpenGL With WGL: wglChoosePixelFormatARB

Posted on February 3, 2013 by iblues1976 Posted in GPU Leave a comment

I will have a WGL (Wiggle) article soon about how to get OpenGL running with Windows. You can find many by searching the web. I do want to prepare a well written article to post here. For now, I will like to comment about a problem that you may find with WGL_ACCELERATION_ARB. In the OpenGL Bible, it has a number 1. While this may work in some computers, some of them (like my BootCamp Mac Windows 7) failed. The solution is to change from 1 to  WGL_FULL_ACCELERATION_ARB

WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, // must be HW accelerated

Look at the source code below.


int pixAttribs[] = { WGL_SUPPORT_OPENGL_ARB, 1,
 WGL_DRAW_TO_WINDOW_ARB, 1,
 WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
 WGL_COLOR_BITS_ARB, 24,
 WGL_DEPTH_BITS_ARB, 24,
 WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
 WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, // MSAA on
 WGL_SAMPLES_ARB, 16, // 16x MSAA
 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
 0}; // NULL termination

 // Ask OpenGL to find the most relevant format matching our attribs
 // Only get one format back.
 wglChoosePixelFormatARB(g_hDC, &pixAttribs[0], NULL,
                   1, &nPixelFormat, (UINT*)&nPixCount);

Freeglut and Visual Studio 2012

Posted on January 28, 2013 by iblues1976 Posted in C++, CG, featured, GPU Leave a comment

*** EDIT : 2/3/2012 ***

If you can’t find the gl.h and glu.h , install the Windows SDK. For example, for Windows 7 you can install Windows 7 SDK (7.1) This will create a directory in Program Files\Microsoft Windows SDK\7.1 where you can find the files include the OpenGL32.dll. (The directory may look different. Mine is : C:\Program Files\Microsoft SDKs\Windows\v7.1 )


I would like to talk about the instructions of installing FreeGLUT in a Windows 7 with Visual Studio 2012. The instructions are similar for older Visual Studio. Windows 8 will also be the same under this instructions.

First, you need to either build the FreeGlut in your Visual Studio 2012 (download the source from here) or getting the binaries (here)

Once you have the binaries, you need to copy the 64-bit Library freeglut.lib to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64

and the 32 bit library to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib

You also need top copy the GL folder from the include. C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include

Finally, you need to copy the DLL into your windows system directory.

For the 64 bit version, place it in C:\Windows\System32 (assuming Windows is pointing to C:\Windows) .. YES, you heard right… System32 is the 64 bit version for windows…

For the 32 bit version, pleace in C:\Windows \SysWow64 (this is the 32 bit version)

You may need other libraries, for example the GLEW Library. Go to this site to download it. Download the pre-packaged binaries (unless you want the source, which you need to compile) They have two versions. 32 and 64 bits. I suggest you download both.

Do the same process. Copy the 64 bit .lib files to  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64 and 32 bit files to  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib

Copy the include folder GL (it will add more files to your GL)  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include

copy the .dll and the .exe to your system32 (for 64 bits) and syswow (for 32 bits)

Also make sure you have the libraries in your project properties as shown in the figure below.

gllib

Computer Graphics Course Notes: Smooth Shading

Posted on January 24, 2013 by iblues1976 Posted in CG, featured, GPU, The Human Compiler Leave a comment

(Practical Linear Algebra by Farin and Hansford from Chapter 8.)

 

For now, I’m only including the pictures of the board. One with Camera Flash and one without. Click on the pictures to get the full size.

Board1 Board2

CG TO GLSL: Series 1 Data Types

Posted on January 15, 2013 by iblues1976 Posted in CG TO GLSL Series, featured, The Human Compiler Leave a comment

I’m trying to do some Volume Rendering. In order to convert the code of the book “Real-Time Volume Graphics” by Engel et el. , I need to learn CG and later GLSL to implemented in GLSL. Why do I want to implemented in GLSL? Well, for one, one of my computers has AMD ATI. While CG may run in here, I did face a few problems. I also want to use this opportunity to understand the code in the book better, and what better way to complicate the heck out of my life, right?

Well, I think is a good exercise. If you are reading this blog, the pre-requisite is that you understand basic OpenGL and have a programming background. Hopefully, a Computer Science background.

Before, I start with the first item to described, the reason that I want to manual translation as opposed to use the CGC compiler to translate from CG to GLSL (which is possible) is to have a more clean output and to learn more. You can convert a vertex shader in cg to glsl. For example to cgc -o v_shader.gl -profile glslv -po version=300 v_shader.cg to convert to a GLSL. However, this GLSL does not look nicely organized… here is an example, of an output of a fragment (for fragment shader use glslf and for geometry shaders use glslg)

CG Version of fp_showGradient.cg (from RTVG book)


#define EPSILON (0.003)

#define GRADIENT_AFTER_TF
half4 main(
 half3 uvw : TEXCOORD0,
 half4 col : COLOR,

 uniform half3 viewVec,
 uniform sampler3D volume,
 uniform sampler1D colortable) : COLOR
{
 half4 valueX1 = tex3D(volume,uvw-half3(EPSILON,0.0,0.0));
 half4 valueX2 = tex3D(volume,uvw+half3(EPSILON,0.0,0.0));
 half4 valueY1 = tex3D(volume,uvw-half3(0.0,EPSILON,0.0));
 half4 valueY2 = tex3D(volume,uvw+half3(0.0,EPSILON,0.0));
 half4 valueZ1 = tex3D(volume,uvw-half3(0.0,0.0,EPSILON));
 half4 valueZ2 = tex3D(volume,uvw+half3(0.0,0.0,EPSILON));
 half4 value = tex3D(volume,uvw);
 half4 color = tex1D(colortable,value.a);

 half3 gradient;

#ifdef GRADIENT_AFTER_TF
 half4 vX1 = tex1D(colortable,valueX1.a);
 half4 vX2 = tex1D(colortable,valueX2.a);
 half4 vY1 = tex1D(colortable,valueY1.a);
 half4 vY2 = tex1D(colortable,valueY2.a);
 half4 vZ1 = tex1D(colortable,valueZ1.a);
 half4 vZ2 = tex1D(colortable,valueZ2.a);
 gradient.x = vX2.a-vX1.a;
 gradient.y = vY2.a-vY1.a;
 gradient.z = vZ2.a-vZ1.a;

#else
 gradient.x = valueX2-valueX1;
 gradient.y = valueY2-valueY1;
 gradient.z = valueZ2-valueZ1;
#endif
 color.xyz = (1.0+normalize(gradient))/2.0;

 return color;
}

after conversion it looks like this:


// glslf output by Cg compiler
// cgc version 3.1.0013, build date Apr 18 2012
// command line args: -profile glslf -po version=410
// source file: fp_showGradient.cg
//vendor NVIDIA Corporation
//version 3.1.0.13
//profile glslf
//program main
//semantic main.viewVec
//semantic main.volume
//semantic main.colortable
//var sampler3D volume : : _volume1 : 3 : 1
//var sampler1D colortable : : _colortable1 : 4 : 1
//var float3 uvw : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1
//var float4 col : $vin.COLOR : : 1 : 0
//var float4 main : $vout.COLOR : COLOR : -1 : 1

#version 410

vec3 _TMP14;
float _TMP16;
float _TMP15;
float _TMP18;
float _TMP17;
vec4 _TMP13;
vec4 _TMP12;
vec4 _TMP11;
vec4 _TMP10;
vec4 _TMP9;
vec4 _TMP8;
vec4 _TMP7;
vec4 _TMP6;
vec3 _uvw1;
vec4 _TMP5;
vec4 _TMP4;
vec4 _TMP3;
vec4 _TMP2;
vec4 _TMP1;
vec4 _TMP0;
uniform sampler3D _volume1;
uniform sampler1D _colortable1;
vec3 _c0023;
vec3 _c0025;
vec3 _c0027;
vec3 _c0029;
vec3 _c0031;
vec3 _c0033;
vec3 _c0035;
float _c0037;
float _c0039;
float _c0041;
float _c0043;
float _c0045;
float _c0047;
float _c0049;
in vec4 cg_TexCoord0;
out vec4 cg_FragColor;

// main procedure, the original name was main
void main()
{

vec4 _valueX1;
 vec4 _valueX2;
 vec4 _valueY1;
 vec4 _valueY2;
 vec4 _valueZ1;
 vec4 _valueZ2;
 vec4 _value;
 vec4 _color;
 vec3 _gradient;
 vec4 _vX1;
 vec4 _vX2;
 vec4 _vY1;
 vec4 _vY2;
 vec4 _vZ1;
 vec4 _vZ2;

_uvw1 = vec3(float(cg_TexCoord0.x), float(cg_TexCoord0.y), float(cg_TexCoord0.z));
 _c0023 = vec3(float((_uvw1 - vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).x), float((_uvw1 - vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).y), float((_uvw1 - vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).z));
 _TMP0 = texture(_volume1, _c0023);
 _valueX1 = vec4(float(_TMP0.x), float(_TMP0.y), float(_TMP0.z), float(_TMP0.w));
 _c0025 = vec3(float((_uvw1 + vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).x), float((_uvw1 + vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).y), float((_uvw1 + vec3( 3.00025940E-003, 0.00000000E+000, 0.00000000E+000)).z));
 _TMP1 = texture(_volume1, _c0025);
 _valueX2 = vec4(float(_TMP1.x), float(_TMP1.y), float(_TMP1.z), float(_TMP1.w));
 _c0027 = vec3(float((_uvw1 - vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).x), float((_uvw1 - vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).y), float((_uvw1 - vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).z));
 _TMP2 = texture(_volume1, _c0027);
 _valueY1 = vec4(float(_TMP2.x), float(_TMP2.y), float(_TMP2.z), float(_TMP2.w));
 _c0029 = vec3(float((_uvw1 + vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).x), float((_uvw1 + vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).y), float((_uvw1 + vec3( 0.00000000E+000, 3.00025940E-003, 0.00000000E+000)).z));
 _TMP3 = texture(_volume1, _c0029);
 _valueY2 = vec4(float(_TMP3.x), float(_TMP3.y), float(_TMP3.z), float(_TMP3.w));
 _c0031 = vec3(float((_uvw1 - vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).x), float((_uvw1 - vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).y), float((_uvw1 - vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).z));
 _TMP4 = texture(_volume1, _c0031);
 _valueZ1 = vec4(float(_TMP4.x), float(_TMP4.y), float(_TMP4.z), float(_TMP4.w));
 _c0033 = vec3(float((_uvw1 + vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).x), float((_uvw1 + vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).y), float((_uvw1 + vec3( 0.00000000E+000, 0.00000000E+000, 3.00025940E-003)).z));
 _TMP5 = texture(_volume1, _c0033);
 _valueZ2 = vec4(float(_TMP5.x), float(_TMP5.y), float(_TMP5.z), float(_TMP5.w));
 _c0035 = vec3(float(_uvw1.x), float(_uvw1.y), float(_uvw1.z));
 _TMP6 = texture(_volume1, _c0035);
 _value = vec4(float(_TMP6.x), float(_TMP6.y), float(_TMP6.z), float(_TMP6.w));
 _c0037 = float(_value.w);
 _TMP7 = texture(_colortable1, _c0037);
 _color = vec4(float(_TMP7.x), float(_TMP7.y), float(_TMP7.z), float(_TMP7.w));
 _c0039 = float(_valueX1.w);
 _TMP8 = texture(_colortable1, _c0039);
 _vX1 = vec4(float(_TMP8.x), float(_TMP8.y), float(_TMP8.z), float(_TMP8.w));
 _c0041 = float(_valueX2.w);
 _TMP9 = texture(_colortable1, _c0041);
 _vX2 = vec4(float(_TMP9.x), float(_TMP9.y), float(_TMP9.z), float(_TMP9.w));
 _c0043 = float(_valueY1.w);
 _TMP10 = texture(_colortable1, _c0043);
 _vY1 = vec4(float(_TMP10.x), float(_TMP10.y), float(_TMP10.z), float(_TMP10.w));
 _c0045 = float(_valueY2.w);
 _TMP11 = texture(_colortable1, _c0045);
 _vY2 = vec4(float(_TMP11.x), float(_TMP11.y), float(_TMP11.z), float(_TMP11.w));
 _c0047 = float(_valueZ1.w);
 _TMP12 = texture(_colortable1, _c0047);
 _vZ1 = vec4(float(_TMP12.x), float(_TMP12.y), float(_TMP12.z), float(_TMP12.w));
 _c0049 = float(_valueZ2.w);
 _TMP13 = texture(_colortable1, _c0049);
 _vZ2 = vec4(float(_TMP13.x), float(_TMP13.y), float(_TMP13.z), float(_TMP13.w));
 _gradient.x = _vX2.w - _vX1.w;
 _gradient.y = _vY2.w - _vY1.w;
 _gradient.z = _vZ2.w - _vZ1.w;
 _TMP17 = dot(vec3(float(_gradient.x), float(_gradient.y), float(_gradient.z)), vec3(float(_gradient.x), float(_gradient.y), float(_gradient.z)));
 _TMP15 = float(_TMP17);
 _TMP18 = inversesqrt(float(_TMP15));
 _TMP16 = float(_TMP18);
 _TMP14 = _TMP16*_gradient;
 _color.xyz = (1.00000000E+000 + _TMP14)/2.00000000E+000;
 cg_FragColor = vec4(float(_color.x), float(_color.y), float(_color.z), float(_color.w));
 return;
} // main end

Now you can see why?

Well, the first part that I wanted to look at was the data types in CG (from the free available user guide that comes with the CG Toolkit)

  • float = 32-bit IEEE floating point (s23e8)
  • half = 16-bit like IEEE floating point (s10e5)
  • fixed= 12-bit fixed point number (s1.10) number,
  • int = 32-bit integer (note that profile may omit support for this type or treated as float)
  • bool = boolean true or false.
  • string = used for queries from the CG runtime.
  • sampler, sampler1D,sampler2D, sampler3D, samplerCUBE, samplerRECT for texture objects
  • Struct with member variables. You can also include member functions if needed.
  • Arrays just like in C.
  • Unsized arrays. For example, float vals[], float vals2d[][],float somevals[10][] and so on…
  • CG supports interfaces. (You can only implement one interface per structure. You cannot combine or extended interfaces)

Remember you can have float4,float3,float2,float1,half4,half3…. and so on. 
Remember that as opposed to C, CG does not have implicit conversion. They must be explicit 

PS: I have to be honest… the data type HALF as the keyword identifier does not make me happy. Could have they used single or something else better… 

I will have a series 2 soon.

Installing Cuda MACOSX

Posted on December 2, 2012 by iblues1976 Posted in Cuda, featured, GPU Leave a comment

Hi,

If you have a GPU enabled device (that most of us do) and happens to be NVIDIA, you can use CUDA.

There are many reasons you may want to use a more standard heterogeneous solution like OpenCL. But if you want to install Cuda in MacOSX, you must follow the instructions given by NVIDIA with one cavet:

When running make, you will notice that it fails. This is because you don’t have an MPI installation. One obvious choice is to install it. In my case, I didn’t care for it. Another choice is to delete the samples that uses MPI. The simples one: Run make and when it fails, run make -k

Recent Posts

  • Streams are not paying song writers.
  • C++, COM, and WinRT (NO CX) and Some C++/cx
  • Analog Input Processing: Blog Post by Pat Wilson from Alt Dev Blog Today
  • How to teach C++: Resources
  • Making a Jam Sandwich — an Algorithm

Quotes

Beware of bugs in the above code; I have only proved it correct, not tried it
~Donald E. Knuth
© Francisco R. Ortega