Simple primative library.

Community Forums/Showcase/Simple primative library.

Ryan Burnside(Posted 2007) [#1]
Hello, I've created a simple primative library for OpenGL users. It is done in blitz but you could convert it as needed. It would be best to call the command inside of an opengl list. This way the overhead is minimized in drawing them. I spell poory. I would greatly appreciate credit if you use this as a base for custom primatives.



Happy coding.

It features:
draw_tube(Hdivisions:Float, vdivisions:Float, Height:Float, radius:Float, capped:Byte)

draw_cone(Hdivisions:Float, Height:Float, radius:Float, capped:Byte)

draw_sphere(Hdivisions:Float, vdivisions:Float, radius:Float)

draw_hemisphere(Hdivisions:Float, vdivisions:Float, radius:Float, capped:Byte)

draw_torus(Hdivisions:Float, vdivisions:Float, radius:Float, radius2:Float)

here is the demo with the code:



jfk EO-11110(Posted 2007) [#2]
Although I'm not really a OGL person, thanks for sharing mate, that's solid work.


chwaga(Posted 2007) [#3]
I was waiting for somebody to make something like this, tho "draw" seems to me like the wrong word to use in a command like this, use "CreateTube(ubercode, ubercode, ubercode)" :D


Ryan Burnside(Posted 2007) [#4]
Hmmm I see some improvements that can be made in optimization. Mostly redundant value calculations. Please pardon the crudeness of the code it is all done from scratch. I guess I may work on optimizations. I'm glad somebody can use this I was worried from the lack of posts. I've been learning OpenGL for some time now and was upset that there wasn't commands to draw simple primitives. Tori become rings you can fly through. Spheres become bouncing balls. Tubes and cones become abstract houses. Primatives can be very fun to use and give your game that 80's feeling. I still need to figure out how to implement Goraud shading. two posts have inspired me further.


Ryan Burnside(Posted 2007) [#5]
OK, the library is now faster since I'm avoiding redundant calculations.

Compile and try please.




Ryan Burnside(Posted 2007) [#6]
I don't know how many people are still following but soon you will have some hightmaps added.

a pic:



jfk EO-11110(Posted 2007) [#7]
What is the max of tris and vertices for a surface, eg. for such a heightmap?


Ryan Burnside(Posted 2007) [#8]
There isn't one currently. The parameters are a simple array of points ( which you could derive from a grayscale image file), and a grid width and height and a variable. Each square has two triangles that make it. I'm trying to get smooth shading working by adding a per vertex surface normal.

basically the function just takes a 2d array with z values and a grid width and grid height variable. This is my first foray into OpenGL procedural work but I think it's looking pretty reasonable. I'm not out to shaft Max3D but as a freeware developer I just can't afford the price.


jfk EO-11110(Posted 2007) [#9]
Well I was refering to the 16 bit max seen in directx, so there we've got a 64k vertices maximum, at least in DX7. Esp. in terrains / heightmaps this usually isn't enough.


Ryan Burnside(Posted 2007) [#10]
Basically it takes a .png and uses grayscale to determine the height of each vertex out of a user defined maximum height. The image pixel count is the vertex count as each pixel is a vertex. I'm still trying to get Goraud shading done, but I will include a file with the new features and what not. I have also included a readme with my general thoughts and goals for this. I've been having a heck of a time with Goraud per vertex normals. Feel free to add them if you can, otherwise expect somewhat of a wait as I feebly try to learn them.

a pic


The file:
http://www.mediafire.com/?dukedpgku3g


jfk EO-11110(Posted 2007) [#11]
Of course I know how heghtmaps work. My question is: can you use a heightmap with more than 65535 pixels ( > 256*256)?

For the gouraud shading - you probably should try some simple code samples, eg. an implenetation in an other basic language, eg. QB, like these:

http://www.ocf.berkeley.edu/~horie/gourad2.zip
http://www.ocf.berkeley.edu/~horie/3dpoly.bas
http://www.ocf.berkeley.edu/~horie/gshade2.bas
(from toshi: http://www.ocf.berkeley.edu/~horie/project.html )

Although - I'm not sure if you really need to soft(as in software)-shade it, shouldn't you let OGL do the job using the hardware?