Importing a Blender Model into OpenGL

Posted: August 31st, 2009 | Filed under: Misc Programming | Comments Off

Recently I was looking for a simple way to export a basic model from blender to use in my opengl code written with c++. After a few searches I came up with nothing and decided to look at all the different ways I could export a blender file. The first that was easy enough to recognize the pattern right away was the the Raw Faces (.raw) format.

I quickly created a very basic (and very bad) model of a cup to see how it looked when I exported the cup in the .raw format. You can export a blender model using this format by first selecting the object you want to export (For whatever reason only the selected object(s) will be exported.) Then go to File -> Export -> Raw Faces(.raw). This is what I got after exporting. There shouldn’t be line wraps, however depending on your monitor you may see them. You can download the file in .raw format here.

0.011633 -0.011633 0.011633 -0.001836 -0.016245 0.011633 -0.001512 -0.011633 -0.011633 0.008956 -0.008956 -0.011633
-0.001836 -0.016245 0.011633 -0.011633 -0.011633 0.011633 -0.008956 -0.008956 -0.011633 -0.001512 -0.011633 -0.011633
0.008956 0.008956 -0.011633 -0.001512 0.011633 -0.011633 -0.001836 0.016993 0.011633 0.011633 0.011633 0.011633
-0.001512 0.011633 -0.011633 -0.008956 0.008956 -0.011633 -0.011633 0.011633 0.011633 -0.001836 0.016993 0.011633
0.011633 -0.001745 -0.011633 0.008956 0.008956 -0.011633 0.011633 0.011633 0.011633 0.016943 -0.002119 0.011633
0.016943 -0.002119 0.011633 0.011633 -0.011633 0.011633 0.008956 -0.008956 -0.011633 0.011633 -0.001745 -0.011633
-0.011633 -0.011633 0.011633 -0.016295 -0.002119 0.011633 -0.011633 -0.001745 -0.011633 -0.008956 -0.008956 -0.011633
-0.016295 -0.002119 0.011633 -0.011633 0.011633 0.011633 -0.008956 0.008956 -0.011633 -0.011633 -0.001745 -0.011633
-0.001512 -0.011633 -0.011633 -0.001512 -0.001745 -0.011633 0.011633 -0.001745 -0.011633 0.008956 -0.008956 -0.011633
0.008956 0.008956 -0.011633 0.011633 -0.001745 -0.011633 -0.001512 -0.001745 -0.011633 -0.001512 0.011633 -0.011633
-0.008956 -0.008956 -0.011633 -0.011633 -0.001745 -0.011633 -0.001512 -0.001745 -0.011633 -0.001512 -0.011633 -0.011633
-0.011633 -0.001745 -0.011633 -0.008956 0.008956 -0.011633 -0.001512 0.011633 -0.011633 -0.001512 -0.001745 -0.011633
-0.011633 0.011633 0.011633 -0.016295 -0.002119 0.011633 -0.013645 -0.001861 0.011633 -0.009766 0.009583 0.011633
-0.016295 -0.002119 0.011633 -0.011633 -0.011633 0.011633 -0.009766 -0.009779 0.011633 -0.013645 -0.001861 0.011633
0.011633 -0.011633 0.011633 0.016943 -0.002119 0.011633 0.014015 -0.001861 0.011633 0.009596 -0.009779 0.011633
0.016943 -0.002119 0.011633 0.011633 0.011633 0.011633 0.009596 0.009583 0.011633 0.014015 -0.001861 0.011633
-0.011633 -0.011633 0.011633 -0.001836 -0.016245 0.011633 -0.001613 -0.013616 0.011633 -0.009766 -0.009779 0.011633
-0.001836 -0.016245 0.011633 0.011633 -0.011633 0.011633 0.009596 -0.009779 0.011633 -0.001613 -0.013616 0.011633
-0.001836 0.016993 0.011633 -0.011633 0.011633 0.011633 -0.009766 0.009583 0.011633 -0.001613 0.014044 0.011633
0.011633 0.011633 0.011633 -0.001836 0.016993 0.011633 -0.001613 0.014044 0.011633 0.009596 0.009583 0.011633
0.009596 0.009583 0.011633 -0.001613 0.014044 0.011633 -0.001311 0.010066 -0.007815 0.006850 0.006819 -0.007815
-0.001613 0.014044 0.011633 -0.009766 0.009583 0.011633 -0.007247 0.006819 -0.007815 -0.001311 0.010066 -0.007815
-0.001613 -0.013616 0.011633 0.009596 -0.009779 0.011633 0.006850 -0.007278 -0.007815 -0.001311 -0.010072 -0.007815
-0.009766 -0.009779 0.011633 -0.001613 -0.013616 0.011633 -0.001311 -0.010072 -0.007815 -0.007247 -0.007278 -0.007815
0.014015 -0.001861 0.011633 0.009596 0.009583 0.011633 0.006850 0.006819 -0.007815 0.010067 -0.001513 -0.007815
0.009596 -0.009779 0.011633 0.014015 -0.001861 0.011633 0.010067 -0.001513 -0.007815 0.006850 -0.007278 -0.007815
-0.013645 -0.001861 0.011633 -0.009766 -0.009779 0.011633 -0.007247 -0.007278 -0.007815 -0.010071 -0.001513 -0.007815
-0.009766 0.009583 0.011633 -0.013645 -0.001861 0.011633 -0.010071 -0.001513 -0.007815 -0.007247 0.006819 -0.007815
-0.001311 0.010066 -0.007815 -0.001115 -0.001287 -0.007815 0.010067 -0.001513 -0.007815 0.006850 0.006819 -0.007815
-0.001115 -0.001287 -0.007815 -0.001311 -0.010072 -0.007815 0.006850 -0.007278 -0.007815 0.010067 -0.001513 -0.007815
-0.007247 0.006819 -0.007815 -0.010071 -0.001513 -0.007815 -0.001115 -0.001287 -0.007815 -0.001311 0.010066 -0.007815
-0.010071 -0.001513 -0.007815 -0.007247 -0.007278 -0.007815 -0.001311 -0.010072 -0.007815 -0.001115 -0.001287 -0.007815

Basically, if you haven’t already noticed, it is 4 sets of x,y,z points. You will not get any of the materials when you export the object only the polygons.

Now that we have our object we will need to be able to display it using opengl. First we must read in and store the points.

CupVectors[3][4][33];

ifstream cupFile;
cupFile.open(“cup.raw”);

for(int z=0;z<=32;z++)
for(int y=0;y<=3;y++)
for(int x=0;x<=2;x++)
cupFile >> CupVectors[x][y][z];

cupFile.close();

Pretty simple code. Store the points, open the file, loop through the points, store the points, close the file.

Now that the cup vertex points are stored we are able to easily display them in opengl with another small loop that will create the triangles and save them in our display list.


12 Slick jQuery Plugins

Posted: August 17th, 2009 | Filed under: General | 8 Comments »

As I have been updating the jQuery links on my @jQueryLinks twitter account there were a couple that really stood out as a way to make just about any site feel slick. So here they are. Enjoy.

1. Gritter – By:@jboesch

jQuery Grown look-a-like plugin

jQuery Grown look-a-like plugin

Plugin Page

Demo


2. jQuery Link Nudging – By: @davidwalshblog

Link Nudging

A jQuery Link Nudging Plugin which is essentially a classy, subtle link animation

Plugin Page

Demo


3. Create The Fanciest Dropdown Menu You Ever Saw

Create The Fanciest Dropdown Menu You Ever Saw

Create The Fanciest Dropdown Menu You Ever Saw


Plugin Page

Demo


4. ColorBox – By: @jacklmoore

A light-weight, customizable lightbox plugin for jQuery 1.3

A light-weight, customizable lightbox plugin for jQuery 1.3


Plugin Page

Demo


5. Interactive, Filterable Portfolio – By: @JoelSutherland

A jQuery Plugin to Create an Interactive, Filterable Portfolio

A jQuery Plugin to Create an Interactive, Filterable Portfolio


Plugin Page

Demo


6. Animated Menu Using jQuery

Nice animated menu using jQuery and CSS

Nice animated menu using jQuery and CSS


Plugin Page

Demo


7. jQuery Ajax delete

jQuery Ajax delete

jQuery Ajax delete


Plugin Page

Demo


8. Galleria

Galleria is a javascript image gallery

Galleria is a javascript image gallery


Plugin Page

Demo


9. Easy Slider By: @cssglobe

Easy Slider 1.7 - Numeric Navigation jQuery Slider

Easy Slider 1.7 - Numeric Navigation jQuery Slider


Plugin Page

Demo


10. Cycle Lite

lightweight slideshow plugin

lightweight slideshow plugin


Plugin Page

Demo


11. Notify Bar By: @DmitriSmirnov

shows a notify bar (like on Twitter's webpage)

shows a notify bar (like on Twitter's webpage)


Plugin Page

Demo


12. Animated Tabbed Content – By: @gayadesign

Animated Tabbed Content

Animated Tabbed Content


Plugin Page

Demo


To Stay up to date with more great jQuery Links follow @jQueryLinks on twitter.


ASP.NET/C# Prompt a Save Dialog Box to Download a File

Posted: May 15th, 2009 | Filed under: ASP.NET | Tags: | Comments Off

To save you all (as well as my future self) the trouble of searching all over the place just to find terrible answers on almost every form post out there. Here is a small ASP.NET/C# code snippet that will prompt the user with the save/open dialog box to download a file.

String FileName = "FileName.txt";
String FilePath = "C:/...."; //Replace this
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath);
response.Flush();
response.End();

For more content types check our http://en.wikipedia.org/wiki/MIME_type#List_of_common_media_types