of3D

So I have been playing around to create a 3d shape addon on for OF. I have been going over examples in the red book.

What I have is very very basic. Just teapots and cubes. It gets tricky with light color and shading.

I want to also build a simple way to load shader files and acess them. Figure I would post what I have and see what people can add.

Thanks,
T

http://www.toddvanderlin.com/OF/of3D.zip

Cool! This will definitely be useful for people to get started with 3D shapes in openFrameworks.

A couple of suggestions:
Make lights a class - this way people can create multiple lights. You could have a base light class that has a lot of features and then have some simple light classes that inherit from that that have some default settings. Or just have 1 light class but have some #defines for different settings. ie DIRECTION_LIGHT, SOFT_LIGHT etc

ofLightsOn(); might be better outside of the drawing commands - as people might want to draw shapes without lighting.

Another thing to look into if you are doing 3D is display lists - they are good to use for complex shapes that stay the same during your app or shapes that get used a lot.

You might want to check out josh nimoy’s objLoader addon in the soon to be released 005 which lets you load 3D obj files into openFrameworks.

Theo

nice thanks theo working on it. Question about shaders. Do you know of any lib for loading and using shaders. I would love to try and compile one in OF or just start building one from scratch.

Hey Todd,

There is some example of shader code here:
http://www.openframeworks.cc/forum/view-…-ht=shaders

And some more info here:
http://www.openframeworks.cc/forum/view-…-ht=shaders

Hope that helps!
Theo

Hey guys. This might be kind of a ridiculous question, but I’m trying to throw lighting into a program i’m working on and i just cant seem to figure it out.

I tried out putting in this of3d code and using it to turn lights on and off, and apply them to vertex shapes that I’m drawing, but it doesnt seem to work. here’s what my draw func looks like:

  
ofCube(100,100,300);  
	ofTeaPot(100,800,300);  
	  
	ofSetColor(100,100,100);  
	  
	glBegin(GL_QUADS);  
		glVertex3f(100,100,mouseX);  
		glVertex3f(100,300,mouseX);  
		glVertex3f(300,300,0);  
		glVertex3f(300,100,0);  
	glEnd();  
  

the lighting is applied to the teapot and cube properly, but the quad shape that I draw doesnt reflect light at all. I assume this is some kind of materials problem, but i dont know how to fix it :confused:

can anyone help out?

thanks!!

Hi,

In order to light stuff in opengl you need to calculate the normals of the polygon faces you are drawing. The library function calls such as the teapot and square already do this for you, but if you make your own shapes you have to calculate the normals yourself.

An example for lighting a cube (without using the library function call):
http://www.gamedev.net/reference/articl-…-le1682.asp

Also
http://cs.anu.edu.au/~Hugh.Fisher/3dtea-…-hting.html

and the opengl red book:
http://glprogramming.com/red/chapter05.html

more stuff out there if you google a little…

haha. wow this is pretty epic.

looks fun

thanks!