Openb3d wrapper

BlitzMax Forums/MiniB3D Module/Openb3d wrapper

markcw(Posted 2014) [#1]
This started off as a source wrapper for Openb3d. I posted it to the code archives but then moved it here because it was not PD code, Openb3d is LGPLv2 which forces you to LGPL your own code if importing the source (ie. static linking). To get around this restriction I made a library wrapper which loads functions from a dynamic library. EDIT: Now the license has been given a static linking exception so the source wrapper is back.

Download: the latest version of the wrapper with examples and my small fixes to the C++ source is available HERE courtesy of GitHub.
You can find the official Openb3d libraries and source HERE.

To install MinGW follow this guide.

The original thread about Openb3d is here and the Freebasic thread is here.
Other Openb3d wrapper threads: 2nd, 3rd.

C++ source: If you want to build the official source yourself on Windows you need GLee from here http://www.elf-stone.com/downloads/GLee/ (I recommend 5.4 or 5.5). You'll need GLee.h in MinGW/include/GL and GLee.lib in MinGW/lib. If you're building my version of the source I already have a copy of GLee.h and GLee.c 5.4 in the src folder, so all you need to do is type "make" or "mingw32-make" in cmd. EDIT: the wrapper now imports from source and uses Glew, so this is not necessary.

Updates:
- Converted source wrapper into library wrapper
- MacOS X supported
- 2d in 3d working with Max2d
- Resizeable canvas with Maxgui
- Docs made, online Blitz3d doc links
- Loading textures from models in subfolders
- Rendering 2d or 3d to texture
- Accessing bones or child entities
- Shader examples
- OOP variables for function types so syntax is like miniB3D
- Maps instead of linked lists for fast library object lookup
- Source wrapper version (since static linking exception)
- Using Glew instead of Glee



markcw(Posted 2014) [#2]
This is some shadow test code.
' stencil_shadows.bmx
' code by KronosUK

Import "openb3dlib.bmx"

Graphics3D 800,600,0,2

Local light = CreateLight(2)
RotateEntity light,45,0,0
PositionEntity light,0,25,0

Local camera = CreateCamera()
PositionEntity camera,-20,10,0

Local plane = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane

For i = 1 To 100
	Local cube = CreateCube()
	
	PositionEntity cube,Rnd(100),0,Rnd(100)
	Local shadow = CreateShadow(cube)
	
	Local cylinder = CreateCylinder()
	
	PositionEntity cylinder,Rnd(100),0,Rnd(100)
	Local shadow1 = CreateShadow(cylinder)
Next

wiretoggle=-1
While Not KeyHit(key_escape) And Not AppTerminate()
	
	If KeyHit(key_space) Then wiretoggle=-wiretoggle
	
	If KeyDown(KEY_UP) Then MoveEntity camera,0,0,1
	If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-1
	If KeyDown(KEY_LEFT) Then MoveEntity camera,-1,0,0
	If KeyDown(KEY_RIGHT) Then MoveEntity camera,1,0,0
	
	If wiretoggle=1 Then Wireframe True Else Wireframe False
	
	UpdateWorld()
	RenderWorld()
	Flip()
Wend



markcw(Posted 2014) [#3]
I got it building on Mac now. You have to edit the c++ source files to use GLee. I also got it to use GLee on ubuntu but it only works with GLee 5.4 or higher.

Here is how to get it working on Mac.

Open in an editor the files: mesh.cpp, shadow.cpp, stencil.cpp, surface.cpp, terrain.cpp, voxel.cpp and replace this:
#ifdef WIN32
#include <gl\GLee.h>
#endif

With this:
#ifdef WIN32
#include "GLee.h"
#endif
#ifdef __APPLE__
#include "GLee.h"
#endif

This means you don't need a copy of GLee.h in MinGW/include/GL now, just one in src along with GLee.c which is less confusing.

Then in material.cpp and texture.cpp you need the same as above but also glu.h is used and Mac stores system headers in an "OpenGL" folder, so replace this:
#ifdef linux
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#endif
#ifdef WIN32
#include <gl\GLee.h>
#endif

#include <GL/glu.h>

With this:
#ifdef linux
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glu.h>
#endif
#ifdef WIN32
#include "GLee.h"
#include <GL\glu.h>
#endif
#ifdef __APPLE__
#include "GLee.h"
#include <OpenGL/glu.h>
#endif

Finally, in project.h there's an include for gl.h, so replace this line:
#include <GL/gl.h>

With this:
#ifdef linux
#include <GL/gl.h>
#endif
#ifdef WIN32
#include <GL\gl.h>
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#endif

And it should now build on Mac. Yay!


degac(Posted 2014) [#4]
Thanks
When I have a little time I will download/change everything!
But there is a ready-to-extract mod of this? Yea... I know, I'm lazy...


markcw(Posted 2014) [#5]
Ok lazy man, or busy man? You can download the library wrapper here

It doesn't have a Mac library file yet though, I have to edit the makefile. I think to avoid license issues I will need to redistribute my version of the c++ source in a separate zip to the library wrapper. I'm not zipping up the source wrapper as I don't think anyone will want that, since it's GPL'd.


Chapman7(Posted 2014) [#6]
Thanks for the Mod folder Munch - there is a problem with that test file that I have had for a while and I have been unable to debug it.

When I zoom out with the camera - I get some weird shadow issues:




degac(Posted 2014) [#7]
Both... busy and when I have a little time... Too lazy!
Thank you very much!


markcw(Posted 2014) [#8]
Hi Chapman. Yes, I've noticed that but I've no idea what's causing it.


markcw(Posted 2014) [#9]
I found the cause. It's from CreateShadow argument 2 Static:String should be a Byte Ptr. Same with all String declarations in the wrappers, they need to be Byte Ptr.

Edit: Well, that isn't quite right. Static should be an Int. It does seem there's a bug when it's set to true.
See post #18 here http://www.blitzbasic.com/Community/posts.php?topic=92800


markcw(Posted 2014) [#10]
I found that Openb3d only loads textures in the same folder as the exe but you can fix this by editing the c++ source. The problem was mentioned here at post #12.

In material.cpp just comment out the Strip() command.
Material* Material::LoadMaterial(string filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count){

	//filename=Strip(filename); // get rid of path info

In texture.cpp
Texture* Texture::LoadTexture(string filename,int flags){
	if (flags&128) {
		//filename=Strip(filename); // get rid of path info

And again in texture.cpp
Texture* Texture::LoadAnimTexture(string filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count){

	//filename=Strip(filename); // get rid of path info



KronosUK(Posted 2014) [#11]
Good work on loadtexture. That used to bug me as it interferred with correct loading of ltextures on models.


degac(Posted 2014) [#12]
Just experimented with Angros OpenB3d mod (using one of Munch's link above - see the first post of this thread)

Everything seems to work (just basic example). I have not tested loaded mesh & co still.

Of course there are many 'new' commands I would like to understand... but documentation is... lacking!

For example:
I found (on freebasic forum) some example (I converted to Bmax) about Octree... but nothing is really clear about how using it!
Same for Shader or Stencil.

Are somewhere tutorials or documentation about this engine (excluding of course the 'Blitz3d' basic commands)?

To be honest it seems a very completed 3d-engine (a sort of Blitz3d extended): it lights me up again on 3d programming :D


markcw(Posted 2014) [#13]
Yes, I would like to provide examples for the extra functions at some point. For now I'm just working on basic functionality, like building a dylib for Mac or getting 2d in 3d working.


angros47(Posted 2014) [#14]
About Octrees: you create it with CreateOctree (width, height, depth), then you can add blocks to it: a "block" can be a piece of wall, a tile, a pillar...
You only need one mesh per type: a single mesh can be used to build many blocks; yous place them using OctreeBlock Octree, mesh, level, x,y,z.
Higher level means that the block will be smaller.

Think about 2d games; you can use tilemaps: you have a limited set of tiles, and place them in a grid, to build a huge world (in old computers, like commodore 64, redefined characters were used to build the game scenario); with octrees, you can do the same in 3d, and build complex worlds (expecially dungeons or buildings... as far as I remember, first Tomb Raider games used a similar approach, too, and also the web plugin 3dml did)


About stencils: they are used to define where the next RenderWorld will update the screen: if you define a stencil mesh, the mesh will become invisible, but when you use the stencil, the next renderworld will render an image only in place where the invisible stencil mesh was (a stencil can also have more than one meshes)... or everywhere but where the mesh was... or only in intersection between stencil mesh and other meshes (useful for portals, spot light and so on).


About LoadTexture: by removing the "strip" command you can load textures in other directories, but be careful: some meshes contains full path for texture names, and when you load the mesh, under windows textures are loaded, but under linux the path is incorrect since it contains "\" instead of "/".


About the mac port... maybe I'll include your patch in next version. I haven't a mac, so I cannot produce a compiled version for it, but if you want to publish your version I can put a link to your site, or include it on sourceforge project.

Nice work!


degac(Posted 2014) [#15]
Thanks for the quick explanation!
I will test with octree 'building' something!


markcw(Posted 2014) [#16]
Hi angros.

Yes, if/when I get the mac port done then feel free to add it to sourceforge.

Thanks for the tips.


markcw(Posted 2014) [#17]
Ok, it works on Mac now. I got stuck because I removed the alpha and stencil buffer flags from graphics3d and then didn't realize there were no shadows because of that. Doh!

So I have uploaded the module with the dylib (and other 2 libraries) and the source as 0.71 (see post#1).

I updated the edits to the cpp files in post#3 of this thread and I'll now mention about the makefile.

I added a CFLAGS variable to make it easier to maintain the gcc lines and removed CCMPILER as it wasn't used. CC is still there but not really needed now. I added glee.o and removed -lGLee from the Windows linking line as there is no library built for Mac by GLee (that I could find) and it's not clear where to put shared libraries on Mac either, so the result is that GLee is now required in src on Windows and Linux. It just made it simple for me. I hope you agree. I also added a make clean. And the -m32 switch is used instead of -arch i386 as that gave an error on Windows. It's all been tested and seems to work fine.


markcw(Posted 2014) [#18]
Well I have an update coming soon, just have to get maxgui working in windows. I now have 2d in 3d with max2d working. Yay! Also now the makefile has a make glee option to speed up compile times by compiling it separately. So you just need to put GLee.h and GLee.c in src then make GLee.o and last make the lib.


Uncle(Posted 2014) [#19]
Excellent new. Looking forward to seeing Max2D working with OpenB3D.


markcw(Posted 2014) [#20]
Okay. New zips up, see my worklog.

There was a bug with fog which appeared with max2d, the solution is to edit camera.cpp so there are no conditions for fog to switch on/off.
	if(fog_mode>0){

		//if(fog!=true){
			glEnable(GL_FOG); // enable if disabled
			if(fog==-1) glFogf(GL_FOG_MODE,GL_LINEAR); // once only
			fog=true;
			Global::fog_enabled=true; // used in mesh render
		//}
	
		...
		
	}else{
		
		//if(fog!=false){
			glDisable(GL_FOG);
			fog=false;
			Global::fog_enabled=false; // used in mesh render
		//}
		
	}


There was also a need to update the global width and height values when resizing a window with maxgui. I failed to load them from the library so I added to functions.cpp.
/*
*/
void GraphicsResize(int width,int height){
	Global::width=width;
	Global::height=height;
}

And to functions.h.
/*
*/
void GraphicsResize(int width,int height);

The makefile changes look like this. GLee.o is not cleaned to speed up compile times, so it needs to be deleted manually.
CC = g++
CFLAGS = -Wall -O3 -m32

OBJECTS = ....

main:$(OBJECTS) 
ifeq ($(shell uname), Linux)
	$(CC) $(CFLAGS) -shared -o libOpenB3D.so $(OBJECTS)  -lGL -lGLU
endif
ifeq ($(shell uname), Darwin)
	$(CC) $(CFLAGS) -shared -o libopenb3d.dylib $(OBJECTS)  GLee.o -framework CoreFoundation -framework OpenGL
endif
ifeq "$(OS)" "Windows_NT"
	$(CC) $(CFLAGS) -shared -o openb3d.dll $(OBJECTS)  GLee.o -lopengl32 -lglu32 -lGDI32
endif


....


glee: GLee.o
	gcc $(CFLAGS) -c GLee.c -o GLee.o


clean:
ifeq "$(OS)" "Windows_NT"
	del $(OBJECTS) openb3d.dll libopenb3d.dylib libOpenB3D.so
else
	rm -rf $(OBJECTS) openb3d.dll libopenb3d.dylib libOpenB3D.so
endif

In Windows maxgui needs SetGraphicsDriver called before CreateCanvas or you get a blank screen. Edit: this is because the default driver in Windows in DX. I gave Graphics3D an extra argument 'usecanvas' instead of a new function as the code was nearly identical.

I also added some docs, it's just links to online Blitz3D docs or else undocumented if extra.

In Mac and Windows if using stencil shadows I needed to set the stencil buffer, on linux it seemed to work with other buffers. So I changed the flags argument in Graphics3D so that it uses everything but the accum buffer by default which is -1. I'm not sure whether I should add the accum buffer as well, I don't think it would do any harm.


Brucey(Posted 2014) [#21]
So, is this going to be faster than miniB3D?


markcw(Posted 2014) [#22]
I don't know, just because it's in c++ I doubt will make much difference.


angros47(Posted 2014) [#23]
@Brucey

Mingw C++ compiler should be faster, since it has a lot of speed optimizations (I don't know, anyway, if Blitzmax optimize the code, too); anyway, OpenB3D uses quaternion-based entities (like Blitz3D, or warner's engine), that are heavier to compute than Euler based rotations (used in MiniB3D). So, it's hard to compare speed of MiniB3D and OpenB3D: they have different features.


markcw(Posted 2014) [#24]
Another update, new zips are up.

This is a fix for the texture loading bug in LoadMesh and LoadAnimMesh not loading textures unless they are all in the same folder as the exe. It assumes the changes in post#10 of this thread about removing Strip() from LoadTexture, etc. So the limitation is textures will load as long as they are in the same folder as the model using them. The function NewFilePath takes the path of the model and uses it for the path of it's texture files.

In texture.cpp include fstream.
#include <string.h>
#include <fstream>

And the two new commands.
Edit: updated to work with 3ds files. NewFilePath() also trys to find the filename in lowercase if it doesn't work as-is. And I tried x files but I couldn't get anything to load.
// strips file info from filepath
string Texture::StripFile(string filename){
	string stripped_filename=filename;
	string::size_type idx;

	idx=filename.find('/');
	if(idx!=string::npos){
		stripped_filename=filename.substr(0,filename.rfind('/'));
	}

	idx=filename.find("\\");
	if(idx!=string::npos){
		stripped_filename=filename.substr(0,filename.rfind("\\"));
	}
	
	return stripped_filename;
}

// makes a new path for a filename from a given filepath
string Texture::NewFilePath(string filepath, string filename){
	string fpath=StripFile(filepath);	
	string fname=Strip(filename);
	ifstream ifs;
	
	ifs.open((fpath+"/"+fname).c_str());
	if(ifs.is_open()){
		ifs.close();
		return fpath+"/"+fname; // Unix
	}
	ifs.open((fpath+"\\"+fname).c_str());
	if(ifs.is_open()){
		ifs.close();
		return fpath+"\\"+fname; // Windows
	}
	
	for(int i=0; fname[i]; i++){ // try filename all lowercase
		fname[i] = tolower(fname[i]);
	}
	ifs.open((fpath+"/"+fname).c_str());
	if(ifs.is_open()){
		ifs.close();
		return fpath+"/"+fname; // unix
	}
	ifs.open((fpath+"\\"+fname).c_str());
	if(ifs.is_open()){
		ifs.close();
		return fpath+"\\"+fname; // windows
	}
	
	cout << "Error: Can't Find Resource File '"+filename+"'" << endl;
	return filename;
}

And in texture.h.
	static string StripFile(string filename);
	static string NewFilePath(string filepath, string filename);

And then implemented in model.cpp.
				te_file=Texture::NewFilePath(f_name,te_file);				
				Texture* new_tex=Texture::LoadTexture(te_file,te_flags);

Edit: and in 3ds.cpp.
void LoadMap(string Filepath){
...
  //If Pixmap <> 0 Then
  Filename = Texture::NewFilePath(Filepath,Filename);
  texture = Texture::LoadTexture(Filename,4);

And in Load3ds().
    case M3D_3DS_MAPFILENAME:
      LoadMap(URL);

Also, I have more examples from minib3d, anim.bmx tests LoadAnimMesh and balls_collision.bmx tests LoadMesh (for b3d). Edit: and MeshesIntersect.bmx tests LoadMesh for 3ds.

The other thing I did was to invert CameraPick's y argument by default so it's the same as minib3d, see camerapick.bmx for the example.
Function CameraPick:Int( cam:Int, x:Float, y:Float )
	Return Int( CameraPick_( Byte Ptr(cam), x, GraphicsHeight()-y ) )
End Function



Chapman7(Posted 2014) [#25]
Munch, was your post (post #9) the solution to the shadow issue or should I ignore it?


markcw(Posted 2014) [#26]
Hi, yes it was. You need to use CreateShadow(ent) or CreateShadow(ent,False) because the 2nd parameter is for static rendering and should only be set to True if you don't intend to move things. Static shadows are only rendered the first time RenderWorld is called.

I'm not sure what's going on with static shadows but it does look like a bug.


Chapman7(Posted 2014) [#27]
Yay! I just tried it out - it's pretty awesome!


markcw(Posted 2014) [#28]
Well I've played around with fixing the static shadows bug/s and I did find a workaround but it doesn't matter because static shadows were actually no faster than realtime shadows. The real limit seems to be how many tris are being rendered by the camera. Edit: I would like to point out this is not a 'solution' as the shadows are not really static, it was just a test to see if this way was any faster.

Anyway, my workaround was just to add a line to shadow.cpp to reset the flag so I could recreate static shadows.
void ShadowObject::Init(){
	VCreated=false;

And then I just freed/recreated the static shadows about every 200 ms to cull/clip the shadow objects. Any less than that and it was slower than realtime shadows and any more and the shadow objects might sneak into view.

If anyone wants to try the code here it is.
' static_shadows.bmx
' based on code by KronosUK

Import "../openb3dlib.bmx"

Graphics3D 800,600,0,2

Local light = CreateLight(2)
RotateEntity light,45,0,0
PositionEntity light,-50,25,-50

Local camera = CreateCamera()
PositionEntity camera,-75,45,0

Local plane = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane

Global cube%[500]
Global cylinder%[500]
Global shadow%[500]
Global shadow1%[500]
Global nshadows=250
Global static=1

For i = 1 To nshadows
	cube[i] = CreateCube()
	PositionEntity cube[i],Rnd(-nshadows,nshadows),0,Rnd(-nshadows,nshadows)

	cylinder[i] = CreateCylinder()
	PositionEntity cylinder[i],Rnd(-nshadows,nshadows),0,Rnd(-nshadows,nshadows)
Next
CreateStaticShadows(static)

' used by fps code
Local old_ms=MilliSecs()
Local renders=0
Local fps=0
Local sh_ms=MilliSecs()

wiretoggle=-1
While Not KeyHit(key_escape) And Not AppTerminate()
	
	If KeyHit(key_space) Then wiretoggle=-wiretoggle
	
	If KeyDown(KEY_UP) Then MoveEntity camera,0,0,1
	If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-1
	If KeyDown(KEY_LEFT) Then MoveEntity camera,-1,0,0
	If KeyDown(KEY_RIGHT) Then MoveEntity camera,1,0,0
	
	If wiretoggle=1 Then Wireframe True Else Wireframe False
	
	'UpdateWorld()
	RenderWorld()
	
	' calculate fps
	renders=renders+1
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	If static And MilliSecs()-sh_ms>=200
		sh_ms=MilliSecs()
		FreeStaticShadows()
		CreateStaticShadows(1)
	EndIf
	
	Text 0,0,"FPS: "+fps
	Text 0,20,"x="+EntityX(camera)+"y="+EntityY(camera)+"z="+EntityZ(camera)
	
	Flip()
Wend

Function CreateStaticShadows(static)
	For Local i = 1 To nshadows
		shadow[i] = CreateShadow(cube[i],static)
		shadow1[i] = CreateShadow(cylinder[i],static)
	Next
End Function

Function FreeStaticShadows()
	For Local i = 1 To nshadows	
		FreeShadow(shadow[i])
		FreeShadow(shadow1[i])
	Next
End Function



markcw(Posted 2014) [#29]
Well I have new examples up taken from minib3d (hope this is ok with simonh) tex_render.bmx uses CameraToTex and cubemap.bmx also uses CameraToTex. Unfortunately though, CameraToTex didn't work for me in Windows (must be a bug) and BackBufferToTex didn't work at all whatever I tried. The cubemap demo was 15fps in Linux so I added a little fudge to render once every 3 frames which put it up to 30fps. Surprisingly, on Mac it was 60fps with or without the fudge.

Then CreateTexture.bmx is a simple example of using GrabPixmap and BufferToTex to render 2d to texture.

Then bones.bmx shows how to access child entities and it uses two functions converted from minib3d, CountAllChildren and GetChildFromAll.

Then some little changes to the wrapper...

I inverted functions with pitch values so it works like minib3d. These were RotateMesh, EntityPitch, RotateEntity and TurnEntity. There may be more to do like DeltaPitch and VectorPitch.

I removed the Static:Int argument for FreeShadow, added the o:Int=1 argument to StencilMode and added the ny:Float argument to VertexNormal. Checked all arguments and they looked fine.

I changed the CreateTexture default argument to flags:Int=9. 8 is a mipmapped flag for distance rendering.

I changed UseSurface surf:Int argument and GetBrushTexture brush:Int argument to be casted to Byte Ptr. I must have missed those.


angros47(Posted 2014) [#30]
By inverting the pitch OpenB3D does not work like minib3d, but more like Blitz3d. Try something like:

TurnEntity entity,90,0,0
TurnEntity entity,0,90,0


Both in OpenB3D and minib3d... you will see the difference. Basically, in minib3d when pitch is close to 90 (or -90) yaw and roll will act in the same way (this is called gimbal lock, and may be a serious issue if you are trying to build i.e. a flight simulator); in OpenB3D yaw will still work in the right way. In fact, OpenB3D works like the fork of minib3d made by warner (http://www.blitzbasic.com/codearcs/codearcs.php?code=2498 , it use the same code), and, as far as I recall, the pitch was inverted in it.

Anyway, when porting code from minib3d, even if you invert the pitch, remember that it will work in a different way.


markcw(Posted 2014) [#31]
I was really trying to mimic Blitz3d not Minib3d.

I just checked in Blitz3d and I do need to invert pitch in those 4 functions to exactly mimic B3d's system, which I believe uses quaternions.

Minib3d uses eulers but there is a quaternion workaround here.

I found a DeltaYaw example here and made a DeltaPitch version and found I need to invert that too. There is an issue with that example where the pointing object can spin round like crazy but it can be solved by zeroing the other axis, so you're limited to using either DeltaPitch or DeltaYaw per entity.

I also needed to invert VectorPitch.


petimat(Posted 2014) [#32]
Well I have new examples up taken from minib3d (hope this is ok with simonh) tex_render.bmx uses CameraToTex and cubemap.bmx also uses CameraToTex. Unfortunately though, CameraToTex didn't work for me in Windows (must be a bug) and BackBufferToTex didn't work at all whatever I tried.

BackBufferToTex() is working but the CameraViewport x,y counts from the bottom-left corner of the screen.(Freebasic+Openb3d)


markcw(Posted 2014) [#33]
Thanks so much petimat! I was really stumped on that one.

I have tested and BackBufferToTex works on Windows too. Yay! It was also nearly twice as fast as CameraToTex in Ubuntu (15 v 25 fps in cubemap.bmx) and that's as fast as Minib3d.

I have a new zip up which just replaces CameraToTex with BackBufferToTex in tex_render.bmx and cubemap.bmx.


petimat(Posted 2014) [#34]
CameraToTex works also but only when the flag is set to 128 (Cubic environment map) in CreateTexture.It doesn't work in any other case.


markcw(Posted 2014) [#35]
In Windows 7 CameraToTex didn't work even with the 128 cubemap flag in CreateTexture. I get a black teapot in cubemap.bmx. CameraToTex uses some kind of framebuffer object implementation, so at a guess that may not work on some gfx cards or drivers (I have Intel GM965 Express).


petimat(Posted 2014) [#36]
Munch!
I wander if you built your own library.
Why don't you just use the one that angros47 builds for freebasic?
He makes some progress on it so you just need to wrap his new functions then.

Anyway,there are functions like BufferToTex and TexToBuffer.Don't you know if we can get the pointer to any buffer somehow?(what these function needs as an argument)


petimat(Posted 2014) [#37]
Here is a shader example for your collection:
Use any diffuse and normal texture.(I used these)
The bump.vert and bump.frag shader comes from Klepto2's minib3d extension.



markcw(Posted 2014) [#38]
Yes, I have several small changes to the c++ source which are not in the official version, so I need to reapply those to the 0.8 source soon. They should all be posted in this thread.

I tried the 0.8 dll in Windows and cubemapping still doesn't work (if that's what you meant).

If you look at my example CreateTexture.bmx it shows you how to use BufferToTex with GrabPixmap, etc. I haven't an example of TexToBuffer as I don't think it has much use.

Thanks for the really nice shader example. I wasn't sure how to do shaders in openb3d as the commands in klepto's minib3d are quite different. So this helps me a lot. :)


markcw(Posted 2014) [#39]
Well I have updated the wrapper to the 0.8 source and the new zips are up.

Here is a summary of my edits. It just lists the first line or most significant line. This is really just a memo for me.
camera.cpp - fog with max2d
 //if(fog!=false){
material.cpp - GLee on Mac
 #ifdef WIN32
mesh.cpp - GLee on Mac
 #ifdef WIN32
project.h - GLee on Mac
 #ifdef linux
shadow.cpp - GLee on Mac
 #ifdef WIN32
stencil.cpp - GLee on Mac
 #ifdef WIN32
surface.cpp - GLee on Mac
 #ifdef WIN32
terrain.cpp - GLee on Mac
 #ifdef WIN32
texture.cpp - GLee on Mac
 #ifdef WIN32
voxel.cpp - GLee on Mac
 #ifdef WIN32
geosphere.cpp - GLee on Mac
 #ifdef WIN32
isosurface.cpp - GLee on Mac
#ifdef linux
particle.cpp - GLee on Mac
#ifdef linux
voxterrain.cpp - GLee on Mac
#ifdef linux

I also needed to add the includes for GLee in geosphere.cpp to get it to build on Mac.
#ifdef WIN32
#include "GLee.h"
#endif
#ifdef __APPLE__
#include "GLee.h"
#endif



petimat(Posted 2014) [#40]
Keep up the good work munch (and Angros47 too),'cause I want to use openB3D with Blitzmax later on :) .(as soon as I can purchase BlitzMax full). As an indie game developer (what I am not but it sounds soo goood :D ) all I need is a 'Blitz3D' with some shadows an simple shaders.
About BufferToTex and TexToBuffer,I'm not sure but I think that would be the key to the post process effects via shaders.We just need the pointers to the backbuffer (framebuffer?),stencilbuffer,depthbuffer.With stencil buffer one could even use blurred shadows.(whee!).But these things are up on Angros47.


angros47(Posted 2014) [#41]
It's a bit more complex: buffers are stored in video memory, not in the RAM, so you can't access them by a simple pointer. That's why there aren't commands like SetBuffer, TextureBuffer and so on: transferring data between video memory and ram can be time-consuming. A texture can be copied from ram to video memory and vice-versa (it's slow, but usually you need to do that only once, so who cares?), and commands like CameraToTex transfer data from a portion of video memory to another, so are fast enough, but messing with buffers is not recommended.

To gain the effects you want, maybe using accumulation buffer could do the trick : currently it's not implemented in OpenB3D, and in MiniB3D it' just used as an antialias, but it should be easy to use (the command is glAccum): I didn't even tried to include something in OpenB3D, because it would have ended in just "wrapping" it with an alias command.


petimat(Posted 2014) [#42]
angros47:
Thanks,that shad some light on the thing.So it should be implemented in the camera.render() function of the source code somehow.That would be a nifty improvement.Anyway I'm happy with this command set openb3d's already got,although I haven't tested all the commands yet. CameraToTex doesn't fully work for me :( .
It's good to see you here answering my stupid questions.


angros47(Posted 2014) [#43]
Here is a demo of blurred shadows in FreeBasic:

http://freebasic.net/forum/viewtopic.php?f=7&t=22745

There is no need to implement it in camera.render(), you can build your own function: if you move entities, instead of lights, you can get a motion blur effect; instead, if you move the camera (but you keep it pointed to the same object by using PointEntity), you should be able to achieve a depth-of-field effect (the camera will have a "focus range": objects too close, or too distant, will be blurred)


markcw(Posted 2014) [#44]
I converted the blur shadow demo to Max. You also need to set the accum flag in openb3dlib.bmx as I haven't set it to be enabled by default but I'll change that.

So in openb3dlib.bmx add "|GRAPHICS_ACCUMBUFFER".
Function Graphics3D( width%, height%, depth%=0, mode%=0, rate%=60, flags%=-1, usecanvas%=False )

	OpenLibrary()
	
	Select flags ' buffer values: back=2, alpha=4, depth=8, stencil=16, accum=32
		Case -1 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER|GRAPHICS_DEPTHBUFFER|GRAPHICS_STENCILBUFFER|GRAPHICS_ACCUMBUFFER

And the demo.
' blur_shadow.bmx
' code by angros47

Import "../openb3dlib.bmx"

Strict
 
Graphics3D 640,480,0,2


Local camera=CreateCamera(0)
Local cube=CreateCube()
EntityFX cube,1

MoveEntity cube,0,0,5

Local plane=CreatePlane()
'Local plane=CreateCube() ; ScaleEntity plane, 100,.1,100
MoveEntity plane,0,-1.4,15

Local light=CreateLight()
PositionEntity light,5,5,5
PointEntity light,cube
MoveEntity camera,0,0,-5

CreateShadow cube


Repeat

	If KeyDown(key_up) Then TurnEntity cube,1,0,0,0
	If KeyDown(key_down) Then TurnEntity cube,-1,0,0,0
	If KeyDown(key_left) Then TurnEntity cube,0,-1,0,0
	If KeyDown(key_right) Then TurnEntity cube,0,1,0,0
	
	UpdateWorld 1

	glClear(GL_ACCUM_BUFFER_BIT)

	For Local i:Int=1 To 20
		PositionEntity light,5+Rnd()*1-.5,5+Rnd()*1-.5,5+Rnd()*1-.5
		RenderWorld
		glAccum(GL_ACCUM, .05)
	Next

	glAccum(GL_RETURN, 1.0)
	Flip
	
Until KeyDown(key_escape)

Of course it's far to slow for realtime use but it might be useful to use them with static shadows if they worked properly.


markcw(Posted 2014) [#45]
I converted the geosphere demo. You need the heightmap as "srtm_ramp2.world.5400x2700.jpg" and texture as "MapOfEarth.jpg" found here. And note that it takes a while to load.

I added collisions but the camera sometimes flies through the geosphere and I couldn't seem to fix it. Also it would be nice to remove the ugly seam created by the edge of the texture. Any ideas?
' geosphere.bmx
' code by angros47

Import "../openb3dlib.bmx"

Strict

Graphics3D 800,600,0,2


Local camera=CreateCamera()
CameraRange camera,.00001,100

Local x=LoadGeosphere("srtm_ramp2.world.5400x2700.jpg")'
'Local x=CreateGeosphere(2700)

Local light=CreateLight()
MoveEntity light,10,10,10
PointEntity light,x

MoveEntity camera,0,0,-45
ScaleEntity x,.01,.01,.01

Local tex=LoadTexture("MapOfEarth.jpg")
ScaleTexture tex,2700,2700
EntityTexture x,tex

Local wiretoggle=-1

EntityPickMode x,2
Local sphere=CreateSphere()
ScaleEntity sphere,.1,.1,.1
EntityColor sphere,255,0,0

EntityType camera,1 ' camera entity type
EntityRadius camera,.03 ' camera radius
EntityType x,2 ' mesh entity type
Collisions 1,2,2,2 ' collisons for entity type 1 and 2, with elipsoid-polygon method and full-slide reponse


Repeat

	CameraPick (camera,MouseX(),MouseY())
	PositionEntity sphere,PickedX(),PickedY(),PickedZ()

	If KeyDown(key_a) Then MoveEntity camera,0,0,.08
	If KeyDown(key_z) Then MoveEntity camera,0,0,-.08
	If KeyDown(key_up) Then TurnEntity camera,-.5,0,0,0
	If KeyDown(key_down) Then TurnEntity camera,.5,0,0,0
	If KeyDown(key_left) Then TurnEntity camera,0,.5,0,0
	If KeyDown(key_right) Then TurnEntity camera,0,-.5,0,0
	
	If KeyDown(key_space) Then TurnEntity x,0,.5,0
	If KeyHit(key_w) Then wiretoggle=-wiretoggle
	If wiretoggle=1 Then Wireframe True Else Wireframe False

	UpdateWorld 1
	RenderWorld

	Text 0,0,"Keys: A/Z=zoom, Arrows=move camera, Space=spin geo, W=wireframe"
	Text 0,20,"x="+EntityX(camera)+" y="+EntityY(camera)+" z="+EntityZ(camera)

	Flip

Until KeyDown(key_escape)



angros47(Posted 2014) [#46]
Geosphere code is still far from perfect. The collision bug might be related to another bug that caused "cracks" on the surface (a known problem on many LOD algorithms): i fixed it in the drawing routine, but I didn't in the coltree routine (I will in the next version).


angros47(Posted 2014) [#47]
I made some tests, the collision issue can be fixed (at least in FreeBasic) by using:

EntityRadius camera,.02


In fact, a radius of 2 is too big: when you move closer to the surface, the surface changes (due to the LOD algorithm), and this might confuse the LOD algorithm (it does not happen with pick commands, since they consider only a line, not a sphere); by reducing radius, only close triangles are evaluated... and LOD algorithm don't change them anymore, so collision routine should work well.


petimat(Posted 2014) [#48]
Thanks angros47. I got the point.
I had to make some change to your freebasic code to work for me.
(screen 18, 32, , &h20002).
However it looks much better without the random lightposition.
glClear(GL_ACCUM_BUFFER_BIT)

for i as integer=1 to 9
    'positionentity light,5+rnd()*1-.5,5+rnd()*1-.5,5+rnd()*1-.5
    positionentity light,sin(i*40)+5,5,cos(i*40)+5
    renderworld
    glAccum(GL_ACCUM, .1)
next

glAccum(GL_RETURN, 1.0)

...and for BlitzMax:
glClear(GL_ACCUM_BUFFER_BIT)

For Local i:Int=1 To 9
	'PositionEntity light,5+Rnd()*1-0.5,5+Rnd()*1-0.5,5+Rnd()*1-0.5
	'best to precalculate the values of sin and cos and put them in an array
	PositionEntity light,(Sin(i*40)*0.3)+3,5,(Cos(i*40)*0.3)+3
	RenderWorld
	glAccum(GL_ACCUM, 0.1)
Next

glAccum(GL_RETURN, 1.0)



markcw(Posted 2014) [#49]
Thanks angros. I was able to increase the entity radius to .03 before the camera started slipping through. I've updated the code snippet.


markcw(Posted 2014) [#50]
I just thought I'd post this up now. It's the per-pixel way to edit textures. It's very simple compared to using max2d for drawing (as in CreateTexture.bmx), no Begin/EndMax2D and no need for LockImage or GrabPixmap.

' CreateTexture2.bmx
' per-pixel access for textures (by munch)

Import "../openb3dlib.bmx"

Graphics3D 800,600,0,2


camera=CreateCamera()
CameraClsColor camera,80,160,240

light=CreateLight()
RotateEntity light,90,0,0

cube=CreateCube()
PositionEntity cube,0,0,3

Local tex=CreateTexture(64,64)

Local map:TPixmap=CreatePixmap(64,64,PF_RGBA8888)
For Local i=0 To PixmapWidth(map)-1
	For Local j=0 To PixmapHeight(map)-1
		Local rgb=Rand(0,255)+(Rand(0,255) Shl 8)+(Rand(0,255) Shl 16)
		WritePixel map,i,j,rgb|$ff000000
	Next
Next

BufferToTex tex,Int(PixmapPixelPtr(map,0,0)) ' buffer takes a byte ptr casted to int

EntityTexture cube,tex


While Not KeyDown(key_escape)

	TurnEntity cube,0.0,0.5,-0.1
	
	RenderWorld
	
	Flip

Wend
End



petimat(Posted 2014) [#51]
Unfortunately it doesn't load any .b3d files exported from gile[s].(unhandled memory exception error). :(


markcw(Posted 2014) [#52]
Try with minib3d and warner engine.


petimat(Posted 2014) [#53]
Works fine with any other engine.It's a test scene from gile[s].(ruinb3d.b3d).Of course I tried more scene but non of them worked.


angros47(Posted 2014) [#54]
Can you put a link to download the file, so I can test it.


petimat(Posted 2014) [#55]
Here it is.


angros47(Posted 2014) [#56]
Ok, I found the cause of the bug: TGA textures are in a format that cannot be read by OpenB3D (if you try to use them to texture a cube, it crashes).

MiniB3D works (even if the .b3d loader is almost the same) because they use BlitzMax functions to load a texture, while OpenB3D uses stb_image.

By upgrading image loader, the issue is fix and the model can be loaded. To fix the bug, just replace the file stb_image.c with this one:

https://raw.githubusercontent.com/nothings/stb/master/deprecated/stb_image.c

(it's not the last version, which I haven't found on the site, but apparently it can manage TGA files used in your model). Compile again, and it should work.


petimat(Posted 2014) [#57]
Thanks Angros47!
My first thought was that probably tga is not supported but then I took a look in iminib3d and it was.I can't compile the source so I just hope it will be there in the next release :).I replaced tga files with png and now it loads the scene.Works as it should.Thanks.

Next: I can't change the texture flag with the TextureFilter command. (e.g. I can load a texture with LoadTexture + flag 4 (masked) but if I load the texture and I want to make it masked with TextureFilter it does nothing)


kiami(Posted 2014) [#58]
Thanks angros47,

I like this project, I am going to try it today.


kiami(Posted 2014) [#59]
All Blitzmax examples works in my system except the one for max2d.

Please add *obj loader for the next version, C++ code for it is everywhere in the internet.

It is important to have 3D library for Blitzmax, even if it is does not use shader. A simple shadow and a simple physics is enough for others to begin work.

Hope you guys continue this project.


angros47(Posted 2014) [#60]
Actually, OpenB3D can use shaders: terrains support fragment shaders only, while meshes supports both vertex and fragment shaders.

The commands are LoadShader, ShadeMesh, ShadeEntity... you just need the .vert and .frag files (in other libraries, there are some "built-in" shaders; in OpenB3D, you need to load them, as you load a texture)

Anyway, since some video cards don't support shaders (or don't have OpenGl drivers that provide shader support), I tried to avoid making the library too shader-dependent: if you have shaders, you can get the best from them, if you don't, well, you can still build a good scene, you don't need to change your video card.


kiami(Posted 2014) [#61]
Thanks, how about loading Wavefront obj model?


angros47(Posted 2014) [#62]
With current version, it's not yet possible. I might add it in the future.


markcw(Posted 2014) [#63]
 All Blitzmax examples works in my system except the one for max2d.

Could you explain what goes wrong? Does the minib3d max2d example work?


kiami(Posted 2014) [#64]
munch,
I see the pot, "press space to ignite fire" does not work, screen becomes frozen without touching anything, I get: "max2d.exe is not responding", also "EXCEPTION_ACCESS_VIOLATIO".

I am using Win 8.1, Nvidia GT 630


kiami(Posted 2014) [#65]
angros46,
*.obj loader for the next version would be great.


markcw(Posted 2014) [#66]
Thanks kiami. Could you try the same max2d example from the latest version of original minib3d?

The CreateTexture example uses max2d to draw onto a texture. Does that work ok? If so then it may be a small issue maybe try LoadImageFont("arial",24) instead of LoadImageFont("Arial.ttf",1).


kiami(Posted 2014) [#67]
munch, max2d works when I use minib3d. Changing LoadImageFont does not help using openB3D.


markcw(Posted 2014) [#68]
Ok. So does CreateTexture.bmx work with openb3d?


kiami(Posted 2014) [#69]
CreateTexture.bmx works fine.

Sorry I cannot help you actively or respond faster, I just can run and give you result because I have to work on another project.


kiami(Posted 2014) [#70]
However, the origin of the problem is:

BeginMax2D() ' MiniB3D function

EndMax2D() ' MiniB3D function

not:

UpdateMax2D() ' your function


angros47(Posted 2014) [#71]
About .obj files: I found these pieces of code:

For Blitz3D (you can port to BlitzMax, of course, if you know both languages)
http://www.blitzbasic.com/codearcs/codearcs.php?code=1323


For BlitzMax and MiniB3D
http://www.blitzbasic.com/codearcs/codearcs.php?code=2125

Looks like the same code has been ported to Monkey, too, to be used in MiniB3d for Monkey.

The BlitzMax code should work on OpenB3D with few changes; maybe I could port it to C++, to integrate it in the library, but actually I'm not sure if it's a good idea: OBJ is a static format, it would not add anything to the library (a mesh loaded with some LoadObj command would be exactly the same as a mesh loaded in .x, 3ds, or static b3d). Also, if we add support for .OBJ, maybe next time somebody will ask to add support to Collada, or LightWave LWO, or Blender... and soon the library would become a mess, with a lot of loaders for format that are seldom or never used. I added support for .3ds and .x because they were already supported in Blitz3D, and I wanted to help porting old program, but I'm not sure about how many format should be supported.

So, instead of trying to support too many formats, maybe would be better to use a separate loader, or to convert the file to something that is already readable: many 3d editors can already save in .3ds (Blender or Anim8or can do that, and they are free), and there are plenty of 3d file converters, for static meshes (most of them can't do animations, because some formats use skeletal, other uses vertex morphing, but since OBJ does not support animations it's not an issue); if you don't want to install a converter, you can even use an online tool, like this:

http://www.greentoken.de/onlineconv/

So, please, try one of the above solution, then let me know if you still need .OBJ support.


kiami(Posted 2014) [#72]
angros47,

Thanks for the links.

I didn't know OpenB3D has support for .x , I didn't look at "whatsnew.txt" in win32 version, I just looked at BlitzMax examples and found b3d support and thought that's all is supported. I thought if only .b3d is supported, then as .obj is easy to implement, then having .obj is a good thing to have in addition to .b3d. I am not specially crazy about .obj loader. Yes, you are right, now with .x, I can convert models to use - I have all kinds of converters. I still do not know if BlitzMax wrapper support .x or .3ds. If it does, I will spend time to find it. And finally, yes, don't waste your time on .obj.


kiami(Posted 2014) [#73]
So, loadMesh in FB loads .x and .3ds. Do I assume that loadMesh loads .x and .3ds in Blitzmax?

About using FB, I will try it, I am not familiar with it, I prefer Blitzmax, but I don't mind to switch. Both fit my philosophy (I am against virual machines if I can, even OOP)! But, I use java everyday!!! Have no choice. Knowing lots of languages, knowing neither one them good enough is becoming our story!


markcw(Posted 2014) [#74]
I tested sample .x files in openb3d and it does not work - afaik it's only .3ds (static) and .b3d (animated).

Testing in original minib3d .x and .3ds do not work.

Re: max2d bug. I don't have Windows 8 so I can't debug this.

Re: loading other 3d file formats. Assimp supports .obj and many more. There is a wrapper for BMax here. Maybe I'll try to add it.


kiami(Posted 2014) [#75]
Thanks munch. I used the c++ version of Assimp when I read "OpenGL Development Cookbook". Having its BlizMax version is a gift. However, I will try Unwrap3D ( http://www.unwrap3d.com/u3d/index.aspx ) to covert my static models to .b3d. Hopefully that will solve my 3d model issue with your wrapper. I have not reached to a stage in which animated 3d is important.


kiami(Posted 2014) [#76]
munch, if wrapper itself work like Blitz3D, I won't need Max2d to work, I guess. Am I right? Or, I am missing something?


angros47(Posted 2014) [#77]
Actually, while .3ds is a well defined file format, .x format encompasses a variety of different (and incompatible) formats: the file can be text-based or binary, animation can be bone-based or vertex-based, version for DirectX 9 is not compatible with DirectX 7... so, many different loaders would be needed (in original Blitz3d it wasn't an issue, since it just uses the loader provided by DirectX sdk, but this is not possible under OpenGL).

In OpenB3D, only text format, and only version 3.2 of model format is supported; so, if your file is i.e. in binary format (you could check by opening it with a text editor), you won't be able to open it in OpenB3D, you need to convert it. I ported the importer from this code: http://www.blitzbasic.com/codearcs/codearcs.php?code=2918


markcw(Posted 2014) [#78]
Well I tried but I can't get the Assimp wrapper working. The problem is that the wrapper uses a specific version of assimp which is no longer available (afaik). I tried updating it to assimp 3.0 and 3.1 but it just spits out errors like "IFCOpenings.cpp:(.text+0x30df): undefined reference to" etc, etc. So I'm giving up and going back to my shader examples.


kiami(Posted 2014) [#79]
Above, I mentioned I can consider freeBasic, but, although freeBasic has a lot to offer, it lacks true GC, hence, I do not see any reason to use it instead of using C++. Thus, to use a BASIC language, I stick to Blickmax until convinced other way.


petimat(Posted 2014) [#80]
Munch,how is it going with the shaders?


markcw(Posted 2014) [#81]
Ok, I am a bit busy at the moment and it's all messy and unfinished but I hope to have some good examples that can be used directly in a game without needing to understand any glsl. I have cubemaps, toon shading, lighting, texture masking, glsl sandbox and some other basic things. I changed how I wrap UseFloat, etc. so you can just put the variable in and no need for Varptr. I also have some basic descriptions for shader functions but I'm still wondering how to use UseMatrix or LoadMaterial.


Ferret(Posted 2014) [#82]
Is OpenB3D using quaternions?

I hate gimbal lock!

I want to port a project that involves flying in space but gimbal lock is a problem for me.


markcw(Posted 2014) [#83]
Yes, openb3d uses quaternions based on warner engine. Sidesign minib3d and minib3d extended use eulers.

Also note that the openb3d wrapper has inverted pitch values in turnentity/rotateentity/rotatemesh to mimic Blitz3d rotations, instead of the Opengl coordinate system.


angros47(Posted 2014) [#84]
@Munch

LoadMaterial is used to load 3d textures: the syntax is the same of LoadAnimTexture, and you can load a strip made of many images; the difference is that images are not frames of an animations, but slices of a 3d texture; you can use them inside a shader, by using ShaderMaterial, or you can use them to create a voxel sprite.

To use a 3d texture, you need to provide 3 texture coords: first, use the command UpdateTexCoords on the surface you want to use, then you can set U,V and W texture coordinates for any vertex (use VertexTexCoords on coordinate set 3)

Note: in original Blitz3D, you could set the W coordinate, but it's ignored:

www.blitzbasic.com/b3ddocs/command.php?name=VertexTexCoords

MiniB3D copied that behaviour; in OpenB3D, instead, the W coordinate finally has meaning, even if it's not too immediate.



About UseMatrix: it's needed when you are using some vertex shaders: in fact, a vertex shader might need, as input parameters, surface data (you can send them by using UseSurface) and camera matrix data (there are two of them: camera matrix, that contains position and rotation info, and projection matrix, that contain zoom and perspective info); to send camera matrix info, you need to use UseMatrix. Unless your shader need that, you can just ignore these commands.


Ferret(Posted 2014) [#85]
Munch, your the man!

I was using MiniB3D with Warners quaternions.
The project now runs on OpenB3D, it runs good and no gimbal lock :)

Thx!


markcw(Posted 2014) [#86]
Thanks very much Angros, that's a big help. I will try to figure the rest out myself.

Ferret. That was quick! Glad it works for you. I'm not sure I follow you though - did you manage to fix gimbal lock in minib3d?


angros47(Posted 2014) [#87]
Before building his own engine, Warner had written an extension for MiniB3d that used quaternions (I'm sure about it, because I converted it to C++ and merged it with iMinib3d... that was how OpenB3D started); I guess Ferret was using it.


Ferret(Posted 2014) [#88]
Yes, i was using Warners extension for MiniB3D.

Porting was easyer then expected, every command i need is there and seems to work, it took me less then two hours.

I do have some minor glitches, not sure if its mi code or OpenB3D.

I have a scene with a skybox, a camera and a point light.
The skybox is parented to the camera, fulbright and colored using EntityColor().

The camera is positiond back a litle so the light is in front of me.
Now when i move the camera on the z axis past the light, the skybox color turns white. When i go far enough, the skybox gets its color back.

This only happens in one direction on the z axis.
Not sure if this has anything to do with the problem but i move the world, not the camera.

I don't understand why a light affects a fulbright mesh.


Ferret(Posted 2014) [#89]
I created a simple example.




markcw(Posted 2014) [#90]
Ok, thanks. I will have a look around for Warner's minib3d extension.

Ferret, it looks like you made a mistake. The LightRange must not reach past the size of the skybox.


Ferret(Posted 2014) [#91]
Yep, it works now, thx!


Ferret(Posted 2014) [#92]
Shaders work :)

Now i have pixel perfect lighting and normal maps, looks nice.


markcw(Posted 2014) [#93]
Sounds good Ferret. I still need to finish a per-pixel lighting shader. I have a nice one from here and the lighthouse3d one from here but it doesn't seem to work very well. Where did you get your per-pixel lighting code from? :)


Ferret(Posted 2014) [#94]
Here is a working example using the Light shader.
https://sites.google.com/site/ferret3ddesign/openb3d

I got it from various sources and managed to create a shader that works for multiple lights (max 8) and has the effects that i want.

I had to adapt it for OpenB3D, it used gl_FrontMaterial.emission wich i replaced with a uniform variable.
You can find the version using gl_FrontMaterial.emission in the backup folder.

You will find more shaders in the shaders folder, i never used those shaders but they might come in handy.


markcw(Posted 2014) [#95]
Great work Ferret. Thanks! I ran the example from ubuntu and it crashed but I fixed it.

I'll just point out the errors. First two in Light.frag.
vec4 base = texture2D(textureB, vec2(texCoords)); // added vec2()

...

            totalLighting += (ambientLighting*vec3(base) + diffuseReflection*vec3(base) + specularReflection); // added vec3()

I also had to set the attribute tangent or it was black. I have been using 0.5 on the xyz axis to average out the light vector so it looks ok from all angles. You could calculate the correct 3d vector in realtime but it's too much maths for me.
SetFloat4 (shad,"tangent",0.5,0.5,0.5,0.5)

Also I found a solution in the Backup/Light.frag for using gl_FrontMaterial.emission instead of the uniform variable. It looks a bit different to yours, no black bumpy shadows. Perhaps better?
            vec3 ambientLighting = vec3(gl_LightModel.ambient) * vec3(gl_FrontMaterial.diffuse); // added diffuse

I also found some very similar Blender code here but it doesn't have a colormap. I actually tried that code but couldn't get it working.


markcw(Posted 2014) [#96]
Actually the change to gl_FrontMaterial.emission doesn't work as it's lost it's bumpiness. It only shows up bumpy under the light. So yours is better. I'm getting a slow fps though 24 vs 35.


DarkGiver(Posted 2014) [#97]
I've something that can interest you (^_^)

http://www.darkgiver.ch/shader_test_01.zip

A lovely shader, including colormap, normalmap, specularmap, and multiple light support, including attenuation.



The main problem was the tangent calculation, and it is now calculated internally in the .frag

Change the variables in shaders file to change the number of lights.

Variable you must set :

texturescale = texture scale factor
lightradius = to calculate the attenuation
vambient = ambient light

It took me a lot of time, but it works fine ! that's why i want to share.

Enjoy !!!

Now i hope a new version of openb3d will be out soon.. especially for a better terrain and shadow support.


Ferret(Posted 2014) [#98]
@Munch, thx for the fixes!

I noticed the framerate drops in the example.
Mi project seems to run fine with multiple planets and a ship using the shader.

DarkGiver saves the day with maths for the tangent :)


@DarkGiver, thx for sharing, looks verry nice!


angros47(Posted 2014) [#99]
About Assimp, D.J.Peters has made a wrapper for Freebasic, and it can be used with OpenB3D:

http://freebasic.net/forum/viewtopic.php?f=14&t=22798


Ferret(Posted 2014) [#100]
Can i load media in a different thread or stream it using Assimp?
Or is there another way to do this in OpenB3D?

I'm loading all media at startup, this works but wastes allot of memory and the more media to load the longer it takes.
It currently loads in under 30 seconds but this will go up when i add more media.


angros47(Posted 2014) [#101]
I never tried using OpenB3D with threads... anyway, Assimp is an indipendent library, so you can use it to load data in another thread with no issues: when you have loaded data, and you start using them to create your mesh (with CreateMesh, AddVertex, AddTriangle and so on), maybe you should use HideEntity on the mesh, and show it only when finished, to prevent that a RenderWorld call from another thread try to access data from an incomplete mesh.
OpenB3D is not thread-safe, so you have to be careful.


markcw(Posted 2014) [#102]
DarkGiver, thank you! That's very nice code. It was exactly what I was looking for. I have it working in my own demo now and it looks awesome.

The bump code from minib3dextended only works for one light and also doesn't compute a tangent. I actually came up with a solution for the tangent which worked, sort of. It was xaxis=xdiff*ydiff*zdiff where diff is the light-camera position but it looked wrong when crossing the zero as the light flicked around so fast, so I decided I was out of my depth and went back to setting tangent to 0.1. :)

I had to edit your code to make it work on my old pc which only support glsl 1.2 so in case you're interested here are my changes. To both.
varying vec2 Vertex_UV;
varying vec3 Vertex_Normal;
varying vec3 Vertex_LightDir[MAX_LIGHTS];
varying vec4 Vertex_EyeVec;

To the vert.
		Vertex_LightDir[i] = gl_LightSource[i].position.xyz - view_vertex.xyz; //added xyz

And to the frag.
//precision highp float;
...
	vec3 map = texture2D(normalMap, texcoord ).xyz; //added 2D
...
void main()
{
...
	vec4 Out_Color; //was uniform
...
	vec4 tex01_color = texture2D(colorMap, uv); //added 2D, was rgba
...
	gl_FragColor = Out_Color;



DarkGiver(Posted 2014) [#103]
ha thank you ! i fixed the files with your changes :) more compatible now i guess.

And i improved the shader a bit too... fixed a few bugs with attenuation: Now works correctly with more than 1 light, including the ambient value.

I added the possibility to change the lightradius value for others lightsources, and if not specified the value used by default is the first one. Array is more elegant but i didn't found a way to pass array from maincode to shader... :P

Can you check if it works fine with your computer ?

Thank you !

http://www.darkgiver.ch/shaders_01.09.2014.zip




markcw(Posted 2014) [#104]
Thanks DarkGiver. The code needed 2 changes to work here. The precision codeword is not supported in 1.2 and the screen was all pink dots until I set final_color to an init value. It also runs a little slower, 24 vs 28.
//precision highp float; //removed
...
vec4 final_color = vec4(0.0); //added vec4


You can't pass whole arrays I don't think but you can link (or bind) separate values. One thing I noticed was arrays of floats were not supported (at least not in 1.2) but I found a workaround by defining a float in a struct. Not sure if it's any use to you but here is a demo anyway. It just verifies you can set the 2nd element of an array, which I represent as a green teapot. :) The commented out bits in the frag are to test if float array works.
' sl_floatarrays.bmx
' using arrays of floats

Import "../openb3dlib.bmx"

Strict

Graphics3D 800,600,0,2


Local camera=CreateCamera()
CameraClsColor camera,70,180,235

Local light=CreateLight()

Local teapot=LoadMesh ("media/teapot.b3d")
PositionEntity (teapot,0,0,3)

Local shad=LoadShader ("","shaders/floatarray.vert.glsl","shaders/floatarray.frag.glsl")

SetFloat (shad,"myColor[0].Float",0.1)
SetFloat (shad,"myColor[1].Float",0.7) ' green
SetFloat (shad,"myColor[2].Float",0.1)

ShadeEntity (teapot,shad)


While Not KeyDown(KEY_ESCAPE)

	TurnEntity (teapot,0,.5,-.1)
	
	RenderWorld
	
	Flip

Wend
End

floatarray.frag.glsl
struct FloatArray{
    float Float;
};

uniform FloatArray myColor[4];
//uniform float myColor[4];

void main()
{
	vec4 aColor = vec4(myColor[0].Float, myColor[1].Float, myColor[2].Float, 1.0);
	//vec4 aColor = vec4(myColor[0], myColor[1], myColor[2], 1.0);
	
	gl_FragColor = aColor;
}

floatarray.vert.glsl
void main()
{
	gl_Position = ftransform();
}



angros47(Posted 2014) [#105]
A little new: I managed to replace that ugly glBegin... glEnd inside terrains. I hope to get rid of them at all; I can't see any speed improvement, but at least OpenB3D should become more GLES compliant, and porting it should be easier.


Ian Thompson(Posted 2014) [#106]
A mobile'ish version (even GLES 1.1) would be great. I ported OpenB3D version, many moons ago to, inline C + GLBasic. It worked well but had to stop short at the mobile platforms due to some legacy OpenGL only code(including unsupported GL extensions).


markcw(Posted 2014) [#107]
Ok, I have a new version up. This has lots of shader examples and adds the tga tweak by angros to the openb3d source. I have also split the wrapper into 2 files for my convenience. The shader examples are a work-in-progress but I thought I should share them now for anyone who may be waiting.

Credits! Ferret's code is bumpmap 2 and DarkGiver's code is bumpmap 3. Thanks for the help.


petimat(Posted 2014) [#108]
Great!
Thanks for the shaders and the TGA support munch.

(There is a typo in functions.bmx:
Return Int( CreateStencil_() )
The underscore is missing...)


markcw(Posted 2014) [#109]
Nice find petimat! Thanks. I've added that to the latest zip.


Krischan(Posted 2014) [#110]
I've just tested the "angros.openb3d-0.8.zip" (folder date 06/12/2014 02:37am).

I have the same problem here in Win7x64 with the Max2D example, it just freezes without any error message even in debug mode (0 fps and the teapot doesn't turn). When I uncomment the BeginMax2D and EndMax2D commands the teapot turns (but the firework doesn't work). I guess it could be the EndMax2D command, when I only uncomment the Beginmax2D command only it stops, too.

And it looks like the examples have serious problem when I switch to Superstrict mode and cast all variables and objects. For example the camerapick test I'm getting a "Compile Error: Identifier 'TCamera' not found".



Beside that - uh very nice framework, which commands are missing? I'm thinking of moving my projects to this once it has the same functionality as vanilla minib3d.


Ferret(Posted 2014) [#111]
I allready moved to this :)

All OpenB3D types return Int, as in Blitz3D, so there is no TCamera.


Krischan(Posted 2014) [#112]
Ah ok. In my projects I really love to use variable casting in Superstrict mode to find bugs easier. So it looks like I must stay with minib3d then.


Ferret(Posted 2014) [#113]
Bummer, i would love to see a Krischan project using OpendB3D.
But i understand and your code still rocks!


Ferret(Posted 2014) [#114]
OctreeBlock makes the cube disappear.




angros47(Posted 2014) [#115]
The cube does not disappear, it just become a "tile" of the octree.

With octreeblock, the same mesh can be used in many places of the octree (a block, like a piece of wall, is meant to be reusable): it is automatically moved (so positionentity is not needed) and scaled to the proper level.

By using level 1 (the third parameter of OctreeBlock) you subdivide the octree only once, so every block will be of a size of 512(half of 1024)... Too big to fit in the viewport. Try setting a level of 9-10.


petimat(Posted 2014) [#116]
There is a SetShadowColor method of the ShadowObject class in the source code.It would be nice if we could set these parameters too. :)
(...to set as the object default,not for every instance.)


markcw(Posted 2014) [#117]
Ok, new update to the wrapper. This implements an OOP style like in minib3d following a post by Brucey.

Sorry if this makes life difficult for anyone but it is for 64bit compatibility and OOP is a major feature of BlitzMax. It also makes openb3d fairly compatible with minib3d projects although the types are really only pointer holders. If you get confused you can hit F1 and the variable names show the types you need for that command.

It's not finished yet but most commands should be working, some probably aren't yet so if you find a command that doesn't seem to work please report it so I can fix it. One problem is that many commands can't accept null objects and this generally will cause a crash.

There is still a final copy of the wrapper using Ints but I won't be updating it any more.


markcw(Posted 2014) [#118]
I'm delighted to say I have a working copy of Peter Scheutz's awesome Assimp module now. And because the wrapper is now OOP I was able to instantly switch from minib3d to openb3d. Yay!

I made it a library wrapper since I couldn't get the original source wrapper to build as it's pretty complex. I used the library built by DJ Peters from the Freebasic site so thanks for the link Angros.

Also, in the wrapper I had to change the TForm... commands to accept null objects.


markcw(Posted 2014) [#119]
I now have a static archive wrapper version (openb3darc.bmx) for embedding the library in executables, thanks to BlitzSupport.

One problem on Mac though, I had to copy libopenb3d.dylib to /usr/local/lib to resolve a linking problem. I also had to sudo rm lib as it said it was not a directory and then sudo mkdir lib and cp libopenb3d.dylib /usr/local/lib.


Brucey(Posted 2014) [#120]
Your definition of UseFloat4_() is incorrect, I think.
You probably meant to define the v args as Float ptr :-)


Brucey(Posted 2014) [#121]
So I've been playing (on OS X so far) with the various sources (openb3d and the wrapper that munch's versions), and have some working modules (with everything compiled and linked together in the usual (static) way).

I had to make some changes to x.cpp to compile it on OS X (mavericks), and I also ripped out GLee and used glew instead (which is already a part of BlitzMax).

I also abstracted out the graphics driver so that I could choose between BRL and SDL for context creation and input handling. So for example, you might choose between:
Framework b3d.b3dglsdlgraphics

or 

Framework b3d.b3dglgraphics

The few examples I've tried seem to work as expected. (except for the "Text" function, which doesn't appear to exist anywhere)

Haven't tried a 64-bit build yet.

And I can't release anything for testing until the license is changed - since everything is statically built-in here, and I don't want to release my stuff in any GPL flavoured license.

Fun fun :-)


markcw(Posted 2014) [#122]
Thanks Brucey. I have updated the library source and wrapper with proper static library support. I updated the makefile so there's a new command "make archive" to build a static library.

Edit: to choose to use either dynamic or static library edit the Import line in openb3d.bmx.

One little issue on Mac is the names of the Mac and Linux .a files are the same except for case and Mac seems to overwrite one. so if it's not working it could be the Linux file, the Mac one is lowercase.

Also, I think maybe my implementation in Graphics3D isn't quite right and might be the cause of the Max2D bug on Windows. So I have tried something a bit different and hopefully someone with the bug will test it for me.


Brucey(Posted 2014) [#123]
Here are some examples of Openb3d using an SDL backend, glew, and compiled for 64-bit on Windows :

b3d_sdl_win_x64.7z (4.7 meg)

Built and tested on my Win7 Pro VM.


angros47(Posted 2014) [#124]
Did you need to do any change to be able to compile OpenB3D for 64 bit?

Because on FreeBasic forum there were some users interested in a 64 bit version, and I never tried compiling OpenB3D to 64 bit yet.


Brucey(Posted 2014) [#125]
I didn't make any specific changes for 64-bit.


BLaBZ(Posted 2014) [#126]
Brucey, I, Love, you.

This is phenomenal news.


LT(Posted 2014) [#127]
That is great news, but when I try to run any of the executables, I get this error:

The program can't start because libstdc++_64-6.dll is missing from your computer. Try reinstalling the program to fix this problem.

I am running Windows 8.1 and copied the whole directory to Programs/ - am I doing something wrong?


Brucey(Posted 2014) [#128]
The program can't start because libstdc++_64-6.dll is missing from your computer

Oh, that's interesting. I thought it was meant to statically link that into the binary. Maybe my compiler options are wrong.


Brucey(Posted 2014) [#129]
Fixed, and re-uploaded : b3d_sdl_win_x64.7z (4.9 meg)

That'll teach me to believe everything I read in the documentation :

* TDM-GCC doesn't link your programs with the libgcc or libstdc++ runtime DLLs by default.




LT(Posted 2014) [#130]
It works now. Yay! :)


markcw(Posted 2014) [#131]
There is an -m64 option for gcc. I can remember on Mac I had to use -m32 in the makefile as it defaulted to 64bit. Mac automatically chooses the cpu architecture when you install the os. On Windows 64bit I think MinGW is 32bit only so it doesn't matter. There's an error saying -m64 is unimplemented.

Works fine here. I assume you're importing the source then Brucey.


Brucey(Posted 2014) [#132]
I assume you're importing the source then Brucey.

As much as I ever am. All modules get compiled into static libraries, and then linked into the final app binary.

On Windows 64bit I think MinGW is 32bit only so it doesn't matter.

The 64-bit TDM MinGW compiles 64-bit by default, and you need to use -m32 to compile 32-bit - so it does both architectures with one package.


Shaggy(Posted 2014) [#133]
Hi munch,
with the new version i get an error....

Local temp:TMesh = CreateQuad()
Local surface1:TSurface = GetSurface(temp, 1)

GetSurface return a (Null Object).


markcw(Posted 2014) [#134]
Hi Shaggy, I have a new version up now which should fix this. It was null because surfaces don't exist for the wrapper until you start accessing them and I hadn't the right code for GetSurface to account for this.

I am using linked lists but am going to change that to maps to speed it up for large projects.


markcw(Posted 2014) [#135]
New version is up using maps instead of linked lists for integrating with the library object instances. Also I added THardwareInfo by klepto2. Also an update to the docs, all types are now listed and highlighted in the code. No update to the examples or library.


markcw(Posted 2014) [#136]
Brucey, bug report. I noticed in sl_sandbox64 that the timer seems to be about 5 times slower than it should be running at. It works fine in 32bit win7.


Brucey(Posted 2014) [#137]
I noticed in sl_sandbox64 that the timer seems to be about 5 times slower than it should be running at.

Heh... so it is. Seems my "translation" for the SDL timer was slightly off...

Max:
CreateTimer creates a timer object that 'ticks' hertz times per second.

SDL:
SDL_AddTimer: interval - the timer delay (ms)


which is not quite the same ;-)

Next time I shall read the small-print!


Shaggy(Posted 2014) [#138]
Hi munch,
thanks for the quick fix. But I have another problem with my ati card R9 270x.
When I use the Source with glee and glfw (window) in c++ then I cannot
use a Cubemap. With a Cubemap i become an error: atiglpxx.dll
In BlitzMax with your wrapper there are no problems with cubemaps.

Have you an Idea where are the problem?

Thanks


markcw(Posted 2014) [#139]
I don't know about using glfw. I would guess you've got a mistake somewhere in your code related to cubemaps if everything else works.


markcw(Posted 2014) [#140]
Update. I forgot to import brl.map as it was working when I just imported the file but not when doing a makemods. Also, I have remove the static library wrapper until angros updates his license.


markcw(Posted 2014) [#141]
Yet another update. I added a nice example for THardwareInfo and I renamed a few files, openb3dlib.bmx is now dynamic.bmx so I've changed the examples to import the compiled module. Also a small change to types.bmx. And the libraries are now in a separate zip. Everything is now on GitHub thanks to this super easy tutorial. Yay!


Ferret(Posted 2014) [#142]
Great work Munch!


petimat(Posted 2014) [#143]
I have a problem with a couple of .b3d files,they are loaded without textures.(e.g. dwarf.b3d from warner's samples).It's loaded properly in minib3d but not in openb3d.Could anybody confirm that?


markcw(Posted 2014) [#144]
Nope, dwarf.b3d works ok here. No idea what could be wrong.


petimat(Posted 2014) [#145]
I don't know either but there must be something wrong with the JPG loader stuff because as soon as I converted the texture to TGA (or any other image format) the problem has solved.


markcw(Posted 2014) [#146]
The image loader Openb3d uses only takes the "standard" type of jpg compression. Maybe this is the problem?


petimat(Posted 2014) [#147]
Probebly, because as I 'resaved' the .jpg image as .jpg (with my image viewer) it worked.


Brucey(Posted 2014) [#148]
MiniB3D probably uses libjpeg, OpenB3D uses stb_image, and I expect Blitz3D uses FreeImage?


markcw(Posted 2014) [#149]
Yes, I think that's right Brucey.

There is two main types of jpg compression used, "standard" is lossy and then "progressive" is interlaced, which depends on whether you need high quality detail or not.


Derron(Posted 2014) [#150]
jpeg is in both modes "lossy". Progressive just adds a map of image data at the front of the file ... so that map contains (simplyfied said) some pixel data to display until the image data was fetched more and more - which then replaces the "unsharp" data.


so the problem is that the image library does not play well with that additional data.


bye
Ron


ErikT(Posted 2014) [#151]
Um this will sound stupid: how do I install it? It's been a while since I used bmax. I've extracted angros.mod into the mods folder and the same with openb3d-library so the folder-tree looks like this -> blitzmax/mods/angro.mod/openb3d.mod/examples/. And I get a "can't find interface for module 'angros.openb3d" on compiling so something's obviously wrong :P Do I need to compile the libraries myself or...?


petimat(Posted 2014) [#152]
No ,you just have to build the modul first.It builds without the libraries ,you only need them in the same folder where your codes are when you run your "game.bmx" or build your exe. (correct me if I'm wrong)


petimat(Posted 2014) [#153]
Just a note about Animate()command :
Neither openb3d nor minib3d plays the animation backwards if negative speed is used... while blitz3d does.


Krischan(Posted 2014) [#154]
Looks good, runs in Superstrict mode now, too :-D But I still can't run the Max2D sample, it crashes (Exception at Renderworld). And which commands are still missing right now? What does it take to achieve version 1.0?


Happy Sammy(Posted 2014) [#155]
Hi all,

Where could we download gile[s] nowadays?

Thanks in advance


petimat(Posted 2014) [#156]
I couldn't find the 2.0 free version either.(I use to have that on my old hdd that broke) It would be nice if someone could upload a copy.


ErikT(Posted 2014) [#157]
@petimat:

Thanks, I got it working :)

In case anyone else wonders you need to use bmk to build the module, like so:

run cmd

go to the blitzmax/bin folder

type in "bmk makemods angros.openb3d" to build it

done


Next: I can't change the texture flag with the TextureFilter command. (e.g. I can load a texture with LoadTexture + flag 4 (masked) but if I load the texture and I want to make it masked with TextureFilter it does nothing)

I got this as well but for me setting flags with LoadTexture doesn't do anything either. I always get a mipmapped texture no matter what. I'll try some different file formats. Only tested with .bmp so far.


BlitzSupport(Posted 2014) [#158]
I finally got around to trying this, and the demos are really cool!

One thing I really used to like with Max3D was playing around with the depth and colour buffers (textures?), where you could read the z-values from the depth buffer as RGB, then write out modified values to the colour buffer for effects like DOF.

However, I was never quite sure how it worked, as special texture handles (underlined below) were provided by Max3D for you to use in your shaders:

//@mode postprocess 

//@vertex 

void main ()
{ 
        gl_Position=bb_Vertex; 
} 

//@fragment

uniform float bright = 1.0;

void main ()
{ 

	vec4 pixel = texture2DRect (bb_ColorBuffer, gl_FragCoord.xy);

	float fragz = texture2DRect (bb_DepthBuffer, gl_FragCoord.xy).r;

	fragz = bb_zNear * bb_zFar / (fragz * (bb_zNear - bb_zFar) + bb_zFar);

	pixel.r = clamp ((1.0 / fragz) * bright, 0.0, 1.0);
	pixel.g = clamp ((1.0 / fragz) * bright, 0.0, 1.0);
	pixel.b = clamp ((1.0 / fragz) * bright, 0.0, 1.0);

	gl_FragColor = pixel;

}


(Note also bb_zNear and bb_zFar, also provided by Max3D.)

Is it possible to do something similar with OpenB3D?


markcw(Posted 2014) [#159]
Hi Krischan, I have updated the wrapper with another fix attempt for the max2d bug. This uses exactly the same gfx init code as minib3d. So give it a try.

Happy Sammy, try this https://web.archive.org/web/20131213164018/http://www.frecle.net/update/download.php [giles_2_beta_4.zip].

BlitzSupport, I have no idea how you would do that.


Happy Sammy(Posted 2014) [#160]
Thanks a lot, munch!!!!!
With the help of the above link, we can get back gile[s] and tree[d] and forum posts relating to gile[s].
https://web.archive.org/web/20110116171149/http://www.frecle.net/index.php?show=projects


markcw(Posted 2014) [#161]
BlitzSupport, the problem is getting the depth buffer data. Angros had a method to access it here. http://www.freebasic.net/forum/viewtopic.php?f=14&t=15409&start=690


petimat(Posted 2014) [#162]
Thanks a lot for the link ,munch!


markcw(Posted 2014) [#163]
No problem Happy Sammy and petimat. Just lucky fredborg never did robots.txt. :)

BlitzSupport, I tried adding DepthBufferToTex to the library and it seemed to work in Linux (I got like a greyscale render) but it MAV'd in Windows (at RenderWorld) so I have rem'd it out for now.


Krischan(Posted 2014) [#164]
Munch, it still crashes. But the CreateTexture.bmx example works. So I compared the two examples and uncommented some lines and it looks like it has to do with the teapot model - replacing this with another model from the media folder still crashes the program. Replacing the model with a simple CreateCube function crashes, too.

The only difference is that BeginMax2D/EndMax2D in CreateTexture.bmx is called once, while in the Max2D.bmx example it is called within the main loop. Adding these two commands to the CreateTexture.bmx Main Loop crashes there, too. So it seems to be that it doesn't like multiple calls of it.

You should investigate this further.

Runs:


Crashes:



BlitzSupport(Posted 2014) [#165]
Thanks for having a look, anyway, munch! Interesting that it seems to work on Linux but not Windows... it sounds like your greyscale render was doing the right thing at least.

Are you able to post an example of using DepthBufferToTex so I can mess about with it? Not that I expect to be able to resolve it, but would be interested in taking a look!


markcw(Posted 2014) [#166]
Yeah, there's an example there sl_dof.bmx (which is just tex_render modified) but you need to find the commented out blocks in the wrapper (dynamic and functions bmx files) then the library (functions and texture cpp&h files) and make the library to test the example.

Also, I regressed your shader code to 110 as my pc only does 120. So it uses texture2d (as texture2drect is 140) which I believe is limited to power of 2 sizes.

I think something is wrong with the DepthBufferToTex code but I couldn't find much about it so gave up. The glTexParameteri line crashes it in Win and GL_DEPTH_COMPONENT may need to have code to use the right bit depth.


angros47(Posted 2014) [#167]
Version 0.9 is online.

As promised, I updated the license to allow static linking, and I removed the glBegin occurrences.

Also, I added support for md2 files, and I introduced a couple of features "borrowed" from minib3d for Monkey: animation mode 4 for manual bone movement, and animation pre-rendering for instanced meshes.

But the main new feature is metaballs support: you can use it to create blobs, and organic-like forms: the algorithm used is called "marching cubes", and maybe in future versions could be used to add even more features (like caverns, a new kind of terrains... but also more "abstract" ones, like generic isosurfaces)

http://sourceforge.net/projects/minib3d/files/


Brucey(Posted 2014) [#168]
Excellent !!

Now we can look forward to perhaps supporting OpenGL ES 2 (Pi, Android, iOS, etc) :-)


BlitzSupport(Posted 2014) [#169]
Thanks, munch/angros, will take a look in the next couple of days!


Brucey(Posted 2014) [#170]
Version 0.9 is online.

Things aren't rendering so well here - on OS X. Most things appear as pure white - for example, the building in the ball collisions demo, but the balls themselves look okay.
Haven't tried it yet on the other platforms.


angros47(Posted 2014) [#171]
Could you post a screenshot?

With 0.8 version did you get a different result?


Brucey(Posted 2014) [#172]
With version 8 everything was working fine on all 3 platforms.

It's almost as if there aren't any images being displayed on the objects.

Could you post a screenshot?

I can do so later. But for now, just imagine certain objects being rendered in white :-)


angros47(Posted 2014) [#173]
So, models are textured.

Do you use "vanilla" 0.8, or a modified one? Because, if you modified the version 0.8 you have to do the same change in version 0.9 (remember that "vanilla" OpenB3D strips path data from texture name.

Also, there is a small change in the texture blending mode: in old version, mode 0 and mode 1 were identical (GL_REPLACE), while in 0.9 mode 0 uses GL_REPLACE, mode 1 uses GL_DECAL; try changing texture blending mode with TextureBlend.

Another change is that I replaced the image loader (that was stb 1.31) with a newer version (1.35), but, unless there is some serious bug in it, the new version should be able to load every file supported by the older version.


feeble1(Posted 2014) [#174]
Try throwing all the texture files in the main folder. I believe Munch altered the texture handling.


Brucey(Posted 2014) [#175]
That's sorted it, thanks folks! :-)


BlitzSupport(Posted 2014) [#176]
@munch: I followed your rebuild instructions (very easy to follow) and... DepthBufferToTex seems to work for me here on Windows 7!

Click!

Will have to experiment, but that certainly looks like it's working.

I noticed your comment about shader code versions -- I have no idea what version I was using, but maybe it's related to your own Windows OpenGL drivers if it works here (and on your Linux side)... ?


petimat(Posted 2014) [#177]
Where can I find those 'rebuild instructions' ?


markcw(Posted 2014) [#178]
I have updated the wrapper and library and source to 0.9. There are 3 new functions wrapped: CreateBlob, CreateFluid and SpriteRenderMode but no example yet. The static wrapper is in along with the new license file.

DepthBufferToTex is back (thanks for the test BlitzSupport!). I tried to update my OpenGL driver but it just said they were already up-to-date. Even though I was trying to install a newer version. :P Btw, I have GL 2.0 in Windows and in Linux it's 2.1 so it may be something to do with that. I updated the sl_dof.bmx example so the texture is rendered to the screen.

petimat, using my version of the source you just "cd" to the src folder then "make glee" and "make". Also, you don't need to make glee on Linux.


GW(Posted 2014) [#179]
Just tried the new version. Awesome job!

btw: the max2d example locks up when it hits 'BeginMax2D'.


angros47(Posted 2014) [#180]
Here I posted an example (in FreeBasic) of the use of metaballs:

http://freebasic.net/forum/viewtopic.php?p=202675#p202675




feeble1(Posted 2014) [#181]
Good luck with your marching cubes terrain. I had trouble with extracting iso surfaces from my maps. I am pretty sure that you are smart enough though!


BlitzSupport(Posted 2014) [#182]
Been playing with 0.9 and cross-referencing to Mark's old Max3D (since that's my only reference for playing with GLSL so far!)...

Decided to strip things down, ending up with this (I've set the textures to the screen size, as that's what Max3D did... confirmed after much searching through its source). As it stands, it sets up the shader but doesn't yet use it:



... but it seems like Max3D automatically updated the display if your pixel/fragment shader wrote to the colour buffer (there was no grabbing of the backbuffer/depthbuffer, or re-rendering, so it looks like it must have all been handled during the rendering process).

In OpenB3D, it seems like the only way I'll get my modified "colorbuf" texture to show using the above code is to create/hide a fullscreen quad (and associated camera), apply colorbuf to the quad, set the shader to apply to it, then:

Repeat

	show main camera
	hide fullscreen quad/camera
	grab colour/depth buffers
	RenderWorld

	[shader modifies colour buffer here?]

	hide main camera
	show fullscreen camera/quad with modified colour buffer as texture
	RenderWorld

Forever


Does this sound like the right way to handle this? (The point being to use the depth buffer values to modify the colour buffer values taken from the full-screen display -- eg. apply a blur based on depth value of each pixel -- then display the full-screen result.)


markcw(Posted 2014) [#183]
Just added the metaballs sample to the wrapper. Cool stuff Angros! Thanks.

Btw, I made a mistake in wrapping CreateBlob so fixed that too. I notice the blobs have a lod and they get blocky very quickly when you move away. So I wonder if it would be possible to set the level of detail higher?

Also I added an example load_md2.bmx but it seems to not load any textures and there is random crashing for no reason.

Krischan, thanks for looking into the Max2D bug. Unfortunately, I don't have any more ideas but maybe I will think of one.

BlitzSupport, I don't know any better way than that, but it will be probably be very slow (being software-based).


Krischan(Posted 2014) [#184]
Damn I can't get it running again with the update. What do I do wrong here?

Warning: resolving _glewInit by linking to _glewInit@0
Use --disable-stdcall-fixup to disable these fixups
C:/Apps/BlitzMax/mod/angros.mod/openb3d.mod/libopenb3d-win.a(functions.o):functions.cpp:(.text+0x9a0): undefined reference to `_Unwind_Resume'
C:/Apps/BlitzMax/mod/angros.mod/openb3d.mod/libopenb3d-win.a(functions.o):functions.cpp:(.text+0xbf0): undefined reference to `_Unwind_Resume'
C:/Apps/BlitzMax/mod/angros.mod/openb3d.mod/libopenb3d-win.a(functions.o):functions.cpp:(.text+0xcb4): undefined reference to `_Unwind_Resume'



angros47(Posted 2014) [#185]
@munch
For md2 files, you need to load and set texture by hand using LoadTexture and EntityTexture: that's not a big issue, since a md2 model can have only one texture, that usually has the same name of the model.

I could not include the texture loading in md2 loader, because it'd try to load a texture in PCX format, that is not supported (you need to convert it to jpg or png, so you have to change name)

About metaball lod: to use higher resolution just change camera range; you could modify lod levels in file metaball.cpp by changing all occurrences of "if (rc*.1>3*l)", but you shouldn't: in fact, metaball surfaces is calculated by computing a scalar field for EVERY node in the camera view: if there are many metaballs this can be really computationally expensive, hence the need of using a lod solution.

Classic 3d metaball demos (there is one in Blitz3d, too) used a smaller grid (i.e. 30 * 30 * 30), computed the scalar field for every node (27000 of them), then built the surfaces: it produced nice results, but metaballs were confined in a "cage" made by the grid.

My solution allows to place metaballs almost everyware, but this would require an almost infinite grid: so, it's impossible to compute it: only the part of it that is in view need to be computed, and the lod allows to have a limited number of nodes


markcw(Posted 2014) [#186]
Krischan, my bad. I didn't test Windows yet. That'll teach me.

It looks like a problem static linking to Glee.


markcw(Posted 2014) [#187]
Ok! The problem was that the archive file needs to be built with the same version of mingw or you get these "undefined reference" errors. I had the same errors as Krischan because I was using tdm 4.7 for Max builds and nuwen 4.6 to make the library (I found out that you have to type "mingw32-make" in tdm instead of just "make").

So I'm thinking I really should do the source wrapper instead of the static library wrapper since it avoids this trouble.


petimat(Posted 2014) [#188]
@angros47

Thanks for the new version.
That metaball thing is fun.The animation mod 4 must be good for changeing "animation to ragdoll" and back (I think.Somehing new to play with).However I couldn't make the .md2 file animate.Animate command has no effect on the model,the SetAnimTime causes an unhandled memory exception error in BliztMax (I didn't plan to use .md2 anyway)

@munch

Thanks for the wrapper,the dynamic linked version works for me.
...and thanks for the build instructions...I managed to extend the library with the SetShadowColor function.(YAY!!)


angros47(Posted 2014) [#189]
If you post a link to your md2 model, I'll have a look.


petimat(Posted 2014) [#190]
It's the one that comes with munch's examples...but I tried zumlin.md2 also (you can find one here!)


angros47(Posted 2014) [#191]
Tried with zumlin.md2, it works here (both linux and win32 version). I can't reproduce your problem.


Chapman7(Posted 2014) [#192]


It's beautiful! (and x64)

Edit: When I used Brucey's SDL module, I got about 4500 average FPS instead of 3800


Chapman7(Posted 2014) [#193]
SDL:



Keep up the good work guys!


markcw(Posted 2014) [#194]
I've included a source wrapper version which I assume is ok now license-wise. It's now the default option in openb3d.bmx.

I deleted the static libraries from github so you have to build your own ("make glee" then "make archive") to avoid the static linking errors if gcc versions are different.

Angros, thanks. I updated load_md2.bmx with loadtexture but strangely on Windows it MAV's on SetAnimTime every time, on Linux it MAV's some times randomly for the same reason. I used the tris.md2 from klepto's demos.

I tried setting different CameraRange values for the metaballs but it doesn't seem to affect them. If I zoom out about 100m they turn into little diamonds. It would be nice if they had a minimum lod so they would always stay blobs.

Chapman7, looks good. I'm a little jealous. :)


Krischan(Posted 2014) [#195]
Hmm I don't get it running. I've copied the contents of angros.openb3d-master.zip, openb3d-library-master.zip and openb3d-source-master.zip to the mod folder and the recompile with "bmk makemods -a angros.openb3d" took more time but has been finished without any errors.

I get the error

Warning: resolving _glewInit by linking to _glewInit@0
Use --disable-stdcall-fixup to disable these fixups
C:/Apps/BlitzMax/mod/angros.mod/openb3d.mod/openb3d.release.win32.x86.a(global.cpp.release.win32.x86.o):global.cpp:(.text+0x2c6): undefined reference to `std::_List_node_base::_M_hook(std::_List_node_base*)'
C:/Apps/BlitzMax/mod/angros.mod/openb3d.mod/openb3d.release.win32.x86.a(global.cpp.release.win32.x86.o):global.cpp:(.text$_ZNSt4listIP6CameraSaIS1_EE5mergeIPFbP6EntityS6_EEEvRS3_T_[__ZNSt4listIP6CameraSaIS1_EE5mergeIPFbP6EntityS6_EEEvRS3_T_]+0x60):


My angros.mod folder currently looks like this: angros.mod.zip

What else need I do here? I don't have a "make" command, can you describe step by step please?


angros47(Posted 2014) [#196]
About metaball lod: a single metaball does not have any surface: the fluid entity has a single surface that is computed every frame (in fact, you set color for fluid, not for blobs, if you look at the demo).

So, determining the lod is not like on a terrain or a geosphere (on a geosphere, the program always know when a geosphere is): a fluid is a huge entity, that is always in view, and always need to be computed. Of course, only the portion inside the view frustum is reconstructed, and the resolution decrease when you get far from the camera. By setting a minimum lod, you'd have a grid that will include a number of node proportional to the squared distance, so either you truncate it somewhere (i.e. by using camerarange), or you'll need too much time to render the scene... even if there is no metaball at that distance!

A workaround, if you don't like the diamond shape, is to add a sphere a bit smaller than the metaball, inside it (of course, it works only if there are no metaballs with negative charge, and the su race is not transparent): when the lod is too low, you will still see the sphere mesh.


Brucey(Posted 2014) [#197]
What else need I do here? I don't have a "make" command, can you describe step by step please?

Munch's process is rather complex. Make this, make that, etc.
I prefer simply to have everything built as part of a module - otherwise one should provide all the parts you will need, pre-built, assuming you would be using a compatible compiler. (Which can work well if you specify all the requirements beforehand)

Not sure why an SDL created context would be so much faster. Cool though :-)


Sashkakuhta(Posted 2014) [#198]
Is it possible to texture the fluid somehow? BTW attempting to texture it leads to messing up the fonts...


angros47(Posted 2014) [#199]
Yes, you can texture the fluid, but you cannot set UV coordinates (they are automatically set by the renderer), since the surface is dynamic.

You can also use a cubemap texture.


markcw(Posted 2014) [#200]
Well I thought I'd just simplified everything with the source wrapper.

Krischan, do you have the src folder in the openb3d.mod folder? Oh you do. I'll have a look at your zip but I have tested it in Windows and it worked fine.

Okay, Krischan I just rebuilt the module from your zip and it works here. So I have to assume you have a problem in your MinGW install.


Krischan(Posted 2014) [#201]
> Okay, Krischan I just rebuilt the module from your zip and it works here. So I have to assume you have a problem in your MinGW install.

Hmm, it compiled here without errors, too. However, I've upgrade my MinGW to the newest version but it still doesn't work. But why did it compile in 0.8 and worked, even with the older MinGW installation? I'd really test your library but I can't :-( You should upload a precompiled, running angros.mod distribution for Windows like Brucey suggests or add detailed step by step install instruction how to build it and what prerequisites are needed currently. I'm very confused reading the whole thread again.

Here is the logfile of my compile attempt:



markcw(Posted 2014) [#202]
The problem with providing precompiled binaries is that there can still be compiler conflicts if the user has a different compiler version. This didn't happen before because you don't get this type of conflict with dynamic libraries, only static libraries (which is also what the source wrapper is and all bmx modules). If you edit openb3d.bmx to use dynamic.bmx and then do a makemods it should work fine if the dll is in examples folder.

If you want to use source.bmx to have it all built into the exe then you should make sure you installed MinGW correctly. The best guide for installing MinGW is here. There is an extra step in Windows that isn't in the other MinGW guide which involves copying the libraries from MinGW to BlitzMax/lib. This is probably what is causing your errors. You need to copy that code, give it a .bat extension, edit the 3 variables at the top, then run it in cmd. Then rebuild all modules. If you have done this step then I don't know what else to suggest.


Brucey(Posted 2014) [#203]
There is an extra step in Windows that isn't in the other MinGW guide which involves copying the libraries from MinGW to BlitzMax/lib.

It's always been a bit of a pain that. Which is why, with the latest bmk for the new compiler, you can now create a folder called MinGW32 in your BlitzMax folder and drop the contents of the standard MinGW install into it, and it will all just work - i.e. you don't need any files in lib, nor ar.exe and ld.exe in bin. That is definitely the way forward, if you ask me. The less stuff to do the better - and the less mistakes to be made!

Also for the new compiler I re-engineered your OpenB3D modules : https://github.com/bmx-ng/b3d.mod
Which is what Chapman7 used. I split things up because I needed to be able to have SDL as a backend also, and I decided to use Glew instead of GLee, since Glew is already part of BlitzMax.
Also looking at replacing the Map stuff (String(Long(ptr))) with a new TPtrMap, which is about 2-3x faster. But I'm still testing that.


markcw(Posted 2014) [#204]
That looks great Brucey. I like the way you reorganized the wrapper. I think I will copy your layout for my version actually, since it makes installing easier and we might as well use Glew if it's a source wrapper. And yes, TPtrMap would certainly be nice to have.


Krischan(Posted 2014) [#205]
Brucey - where do I get the SDL stuff?

> Compile Error: Can't find interface for module 'sdl.glsdlmax2d'


Chapman7(Posted 2014) [#206]
https://github.com/bmx-ng/


Krischan(Posted 2014) [#207]
Doesn't work, i'm getting errors on compiling sdl.mod



Ok guys you've won, I must stay with vanilla minib3d and OpenGL 1.0 until I die. This still works even if my whole Blitzmax installation is screwed up now :-( It would have been too nice, now I'm depressed.


Chapman7(Posted 2014) [#208]
Krischan are you using Brucey's BMK-NG and BCC? Because I think the SDL and OpenB3D modules are needing to be used in conjunction with his modified BRL and Pub modules. and I think his modified modules can only be compiled with his modified BMK and BCC

Someone correct me if I am wrong


Derron(Posted 2014) [#209]
You are right - because Brucey has split certain things in brl.system because they contained dependencies (x11 etc.).

So if something needs "sdl.mod", it needs brl-ng and pub-ng - and of course bmx-ng and bcc-ng.

If you are able to get rid of "sdl", you should be able to run it in vanilla bmx too.


bye
Ron


Krischan(Posted 2014) [#210]
This is a paper chase, right? Ok, I've downloaded all of Bruceys BMK-NG modules now, created the bcc.exe and bmk.exe with BLIde first in Release/Non-GUI Mode and copied the two new executables and the core.bmk and make.bmk to the bin folder. I've deleted the brl.mod, pub.mod and maxgui.mod folders and copied the sources there. After that I've recompiled all modules in BLIde manually which took some time. Is this some kind of initiation ceremony to get so far?

Versions:
bcc[ng] Release Version 0.26
bmk 2.22 win32-x86 / gcc 040801 (cpu x8)

Now, Bruceys b3d.mod examples work (except the Max2D example which still crashes) but I can't compile some 3rd party modules anymore, for example sidesign.minib3d or my own module or some from the bah.mod folder. The BRL-NG MaxGUI doesn't compile, too.

Guys, this is getting more and more complex, how about a simple solution for dummies like the minib3d module in a box? I just want to code cool stuff and don't waste my time with compiler errors. Again, a lost evening.


Chapman7(Posted 2014) [#211]
Krischan the BMX-NG stuff is still being developed. There isn't going to be a "solution for dummies" for a little while. You got it working for the most part, but as you said, there are errors and some things don't compile.

Just stick with Munch's wrapper


Krischan(Posted 2014) [#212]
Ahh ok. I thought and it looked like it is some kind of final version. Ok, then I have to wait - I can only experiment in this stage with OpenB3D though it looks very promising.


markcw(Posted 2014) [#213]
I must stay with vanilla minib3d and OpenGL 1.0 until I die.

Krischan, you have OpenGL 1.0!? Do you have a very old pc? It may be this is why Max2d crashes on you.


Krischan(Posted 2014) [#214]
> Krischan, you have OpenGL 1.0!? Do you have a very old pc? It may be this is why Max2d crashes on you.

Hmm, I really should think about a replacement of my old Late 2013 iMac, the nVidia GTX 780M is *very* outdated now ;-) Just kidding. To be more precise - as far as I know, miniB3D uses only OpenGL 1.x commands, please correct me if I am wrong.

According to the OpenGL Extensions Viewer it should be much more than sufficient (OpenGL 4.4 and all Core features up to 4.4 are at 100%) - so I doubt that the problem lies within my system. And I'm running Windows native here on this iMac using Bootcamp, no virtualisation:





Derron(Posted 2014) [#215]
You created an "BlitzMaxNG"-package.

Now you are able to reinstall BlitzMax to another directory - so everything works like before - but now you are able to fetch new updates of bcc/bmk/brl/pub/openb3d for "NG".

@Modules which do not compile
Some of them just need small fixes (eg. you extend from a type having "method my:int()" while yours is "method my()" - just use the same method/function/... definition -> SuperStrict will help).

I assume that YOUR modules wont have really hard problems ... if things wont compile, it might be a bug in BCC (NG) and reporting them to Brucey could help getting rid of them.

Feel free to create issues on github - or create a "Bugs in BCC"-Thread in the "Brucey section" of the board.



bye
Ron


Brucey(Posted 2014) [#216]
... the BMX-NG stuff is still being developed.

Indeed. I only mentioned the B3D build for the purpose of Munch being aware of it.

At the moment, on Windows at least, it's something that requires you to get your hands dirty, and is a bit fiddly to set up if you aren't used to messing around with modules and whatnot.

Other talk of it here is somewhat Off-topic, sorry.

Back to OpenB3D discussions! :-)


Chapman7(Posted 2014) [#217]
(This is using Brucey's OpenB3D wrapper)

The Max2D example does not work. It draws the TeaCup and text (from DrawText in the UpdateMax2D() function) but it just freezes after the first flip.

I had to scrap most of the UpdateMax2D() function because the NG compiler was having an issue with TList. So I just left DrawText in it so I could know when it works.

I narrowed down the app freezing to one command in the wrapper's EndMax2D function:
glEnableClientState(GL_COLOR_ARRAY)

When I comment it out, I can see the DrawText, the TeaCup rotates, and the app doesn't crash. Obviously though, the color/brightness is messed up. And while the DrawText works, DrawImage gives an "EXCEPTION_ACCESS_VIOLATION" error

I don't know what to try from here. Any ideas?


markcw(Posted 2014) [#218]
I think that could be the problem Chapman. Thanks. It seems glEnableClientState is deprecated in modern OpenGL versions. You could try commenting out those 3 lines in EnableStates. Strange how minib3d works though.

I tested Openb3d on my old pc with OpenGL 1.2 and max2d.bmx worked but cubemap.bmx didn't (cubemaps were introduced in 1.3) and shaders didn't (glsl 110 was introduced in 2.0).


Chapman7(Posted 2014) [#219]
Didn't work. glEnableClientState worked for the other two... it's only GL_COLOR_ARRAY that gave me the problem


markcw(Posted 2014) [#220]
Well thanks for trying. I'll have to admit this is really beyond my abilities to solve. I'm not a 'GL guy' and I'd need to buy a new pc to test and I don't think that's going to happen soon. It would be a good idea to look elsewhere if you really need 2d in 3d, like BLaBZ engine.


angros47(Posted 2014) [#221]
OpenB3D expects the GL_COLOR_ARRAY state not changing between one call to RenderWorld and the next one. The status is stored in the internal variable Global::fx2 . So, if you used glEnableClientState(GL_COLOR_ARRAY) , you should either set the flag to 1, or use glDisableClientState(GL_COLOR_ARRAY) before calling RenderWorld.

Otherwise, the command glDrawElements (internally used by OpenB3D) will try to use color data, although they are not binded (unless the mesh fx is set appropriately), and this will result in an error.


Derron(Posted 2014) [#222]
If you use NG + pub.mod-NG your image loaders will possibly be broken. It works if you use "framework", but as soon as another fileformat-loader is trying to load your image (eg. brl.TGALoader before brl.PNGLoader) you will have "LoadImage" return null - even if the image exists.

I made a fix for this but brucey annotated that it still misses some thing (but at least I was able to run digesteroids with "NG" again).


bye
Ron


Krischan(Posted 2014) [#223]
Ok good news - I got it running finally using Bruceys MinGW installation guide. But there was one problem - I still got errors and so I studied the script and copied all files from the MinGW\lib\gcc\mingw32\4.7.1\ folder manually to the Blitzmax\lib folder and overwrote all of them - and then it worked! Seems like the script has missed some files. Strange.

Now only the Max2D problem is open. Angros47 solution works, just add the glDisableClientState(GL_COLOR_ARRAY) command before calling RenderWorld:






Brucey(Posted 2014) [#224]
If you use NG + pub.mod-NG your image loaders will possibly be broken.

I don't think anyone had a problem with it in this thread...

Angros47 solution works, just add the glDisableClientState(GL_COLOR_ARRAY)

Great! So the wrapper probably needs to work off that flag instead.


Derron(Posted 2014) [#225]
I just assumed as people tried it with "NG" and chapman wrote this (which is the same error people had with digesteroids and NG):

And while the DrawText works, DrawImage gives an "EXCEPTION_ACCESS_VIOLATION" error


So sorry if I brought up confusion.


bye
Ron


Chapman7(Posted 2014) [#226]
I was indeed talking about Brucey's wrapper + NG. I was messing a little with the modules though - so i'll have to make a clean install and see if I get the same issues


feeble1(Posted 2014) [#227]
Here's a question: is there any particular reason why Newton was removed from MiniB3D Ext when it was turned into I MINIB3D?
I was just thinking that it should be terribly easy to plug it into OpenB3D.


Chapman7(Posted 2014) [#228]
Follow up question to feeble1's question. Why did Max3D choose ODE over other physics engines?


feeble1(Posted 2014) [#229]
Pulled Newton out of Ext to run in vanilla MiniB3D. It was way easier than I thought.
Have a play with it Chapman7 Newton for MiniB3D

It would take a bit more tinkering to get it into OpenB3D. The TVector type, handling of Quaternions, and a couple of other bits.


markcw(Posted 2014) [#230]
Ok, I have updated my repos with the Max2d fix by Angros, thanks*10 to him. Thanks also to Krischan and Chapman7 for their help, I'm REALLY glad that bug is fixed! lol. I have done the flag fix as Brucey suggested adding the function SetColorState so it just needs a final test. Thanks.

Angros, do you know why GL_NORMAL_ARRAY does not crash? Should I not set that flag too?

Brucey, I copied your b3d.mod as much as I could, but I left out the sdl module and kept the option for loading a dll and I am still using GLee because I couldn't get Glew working in Windows. I get undefined reference errors for glew functions. :( I can't understand how you can use #include "glew.h" in .cpp without needing the glew files in the same folder. I'm also wondering why you Import "*h" in .bmx as it builds fine without them.

I also inverted CameraViewport's y argument so it has the same syntax as minib3d. This can be tested in cubemap.bmx, maxgui.bmx and tex_render.bmx.

Oh, and I removed the "make glee" thing from the makefile, so it's just "make" or "mingw32-make" now.


angros47(Posted 2014) [#231]
GL_NORMAL_ARRAY is usually enabled (unless you set EntityFx mesh,1), so normals data are loaded; if you mess with glEnableClientState and you don't correct the flag, maybe some entities will be rendered without using normals, but it won't crash.

A crash might occur if the first and the last entity rendered have the fx flag set to flat shading (the last rendered entity leave normals disabled, the first rendered entity in the next RenderWorld expects to have it still disabled and don't load normals data)

So, it's a good idea to set fx1 flag, too.


Krischan(Posted 2014) [#232]
Great! Works 99% like a charm. You could mention that the built order is:

bmk makemods -a angros.openb3dlib
bmk makemods -a angros.openb3d
bmk makemods -a angros.b3dglgraphics

There is one thing: the load_md2 example crashes. Uncommenting this line shows the model loaded, so the function has an issue:
SetAnimTime(ent,anim_time#)

Another issue (if it is one) is in the stencil_shadows example. When I increase the number of cylinders and scale them to height, there are some strange shadow artefacts in the screen/camera center, they stay there independent from the camera moves.



Example:


All other examples work perfect from my point of view. What else is left to advance to version 1.0 now?


Brucey(Posted 2014) [#233]
I can't understand how you can use #include "glew.h" in .cpp without needing the glew files in the same folder. I'm also wondering why you Import "*h" in .bmx as it builds fine without them.

That's what the *.h does - it tells BlitzMax the directories where header files are. These are then added to the compiler command-line. That's how glew.h works from a different location.


markcw(Posted 2014) [#234]
Brucey, I'm still stuck on glew. I got the glew version to build on Mac/Linux but not Windows.

I was using tdm 4.7 but found it doesn't have glew in it so I thought maybe a lib is missing. So I went to nuwen 4.6, did the .bat file thing and also copied libglew32.a to BlitzMax/lib and rebuilt all modules still errors.

Before that I tried throwing the glew source into openb3d/src with the same results.

I am suspecting this is a bug with bmx. I had a similar problem before in Windows where I couldn't put .a libraries in a subfolder (ie. Import "lib/libopenb3d.a") and it only worked from the same folder - but on Linux it worked.

Here are the errors, they've been the same each time.
Building balls_collision
Compiling:balls_collision.bmx
flat assembler  version 1.69.14  (1615296 kilobytes memory)
4 passes, 15665 bytes.
Linking:balls_collision.debug.exe
C:/BlitzMax/mod/angros.mod/openb3dlib.mod/openb3dlib.debug.win32.x86.a(texture.cpp.debug.win32.x86.o):texture.cpp:(.text+0x1a53): 
undefined reference to `_imp____glewGenFramebuffers'
...

Edit: fixed! I had to add #define GLEW_STATIC on Windows in every c/cpp file including glew.h. Edit: now improved by adding this to openb3dlib.mod.
?Win32
ModuleInfo "CC_OPTS: -DGLEW_STATIC"
?



markcw(Posted 2014) [#235]
Angros, thanks again. I changed SetColorState to a general SetRenderState and added an extra argument (capability) so I can set fx1 and fx2 and any more I find later.

Krischan, did you have trouble using "bmk makemods -a angros"? It seems to work for me on Windows. You're right about the order though.

I also get the md2 SetAnimTime crash. It seems to happen when SetAnimTime is zero. Try setting Local anim_time#=0 in to 0.1. Edit: this works but in Windows it still crashes randomly, if it gets loaded then it animates fine. Edit: now the random crashes are gone in Windows when using glew instead of glee. Strange.

The stencil shadow casters are hidden inside the object, so using RotateMesh exposes the caster but using TurnEntity hides it, perhaps because the shadow isn't able to update in time. I couldn't fix the ScaleEntity issue but you can add FitMesh cylinder[i],-1,-1,-1,2,5,2 before CreateShadow and it will work fine.

Edit: updated angros.mod with these changes.


Krischan(Posted 2014) [#236]
I've spent some time with openB3D and found that the 2D mode still has a problem, I've made a lighting/shader example for it, once with miniB3D and once with openB3D:

OpenB3D_Milkyway.zip (1.5MB)

The variable "test" ist set to 1 in the miniB3D example and 0 in the openB3D example, it just shows or hides the 2D mode. When you press SPACE the value gets switched. miniB3D works but openB3D crashes here. The source is nearly identical, with openB3D using a shader for the lighting of the moon as a difference.


markcw(Posted 2014) [#237]
Krischan, thanks for the demo. Very nice!

I have updated the wrapper to account for all occurrences of passing null objects to functions which was causing crashes for me. I had only done this for some functions but now I realize it's an issue the wrapper needs to fix - passing null objects is okay but not fields of null objects so a check is needed (now renamed from EntityExists to IsObject).

Second, your frag shader wouldn't work on glsl 120 here. Just 3 changes were needed.
varying vec3 normal,vert; // rem in

varying vec2 texCoords;
uniform sampler2D tex0;
uniform float intensity;

void main(void)
{

	vec3 lp=gl_LightSource[0].position.xyz;
	vec3 ld=normalize(lp-vert);
	vec3 ed=normalize(-vert);
	vec3 r=normalize(-reflect(ld,normal));
	
	vec4 la=gl_FrontLightProduct[0].ambient;
	vec4 lf=gl_FrontLightProduct[0].diffuse*max(dot(normal,ld),0.0);
	vec4 ls=gl_FrontLightProduct[0].specular*pow(max(dot(r,ed),0.0),gl_FrontMaterial.shininess);
	
	vec4 pixel = texture2D(tex0, texCoords);
	vec4 light = gl_FrontLightModelProduct.sceneColor+pow(la+lf+ls,vec4(0.75)); // add vec4

	gl_FragColor=mix(vec4(0),light*intensity,pixel*intensity); // add vec4
	//gl_FragColor=light;
	
}

Third, there seems to be a bug with Openb3d when EntityFX is set to 1. So it crashes until you edit in TMilkyway.bmx the line "EntityFX Starbox, 1" to any value not including 1. This seems to only happen sometimes but I was able to reproduce it.

Fourth, when I press space max2d seems to disable the alpha blending for the stars, etc. I am not sure what is causing this. I'll try making a simplified example.


angros47(Posted 2014) [#238]
When EntityFX is set to 1, normal data are not binded to the mesh, but the shader included in the example seems to require normal data (it uses gl_Normal); could it be the cause of the crash?

About alpha blending: max2d includes the command "glDisable(GL_BLEND)"; you should inform OpenB3D, by setting the variable "Global::alpha_enable=false;"


markcw(Posted 2014) [#239]
Thanks angros! I have fixed these bugs now I hope. New version is up.

The EntityFX 1 bug wasn't to do with the shader but it was because the normal data was not binded. When fx1 was 1 and Max2d was used then it crashed. So I just set fx1 to 0 in EndMax2d.

The alpha blending issue was solved by setting alpha_enable to 0 in EndMax2d.

The fog bug was where you couldn't have Max2d and fog together. I had to edit camera.cpp in Camera::Update to move the fog commands outside the conditional statements.

The other thing I did was to add setting vbo_enabled at GraphicsInit from THardwareInfo.


Brucey(Posted 2014) [#240]
So I just set fx1 to 0 in EndMax2d. ... setting alpha_enable to 0 in EndMax2d.

Wouldn't it be better to record what the values are *before* Max2D, and then re/setting them *after* Max2D, rather than always setting them to some constant value?

I just assume it would be nice to leave things in the same state that they were previously?


Krischan(Posted 2014) [#241]
Hmm I'm getting a compiler error with the current snapshot (my previous version still compiles):




ErikT(Posted 2014) [#242]
I have the same compile error as Krischan. Also, LoadAnimSeq seems to be missing? I get 'Identifier 'LoadAnimSeq' not found' when I try to use it.

In any case, very cool project :)


markcw(Posted 2014) [#243]
Brucey, I wasn't sure about your question so I added GetRenderState to test and while I got it working it just made the code confusing. Then I realized you can use constant values as Max2d has a constant effect on the states - it always disables the 3d buffers and states, like blending.

Krischan, sorry about that. I was using gl constants in SetRenderState and GL_ARRAY_BUFFER is an extension in glew which is not included in functions.cpp so I dropped the gl constants and used my own enums. Strange how it compiled for me.

ErikT, yes it isn't there. If you look at the bottom of functions.cpp it shows a list of todo functions which includes LoadAnimSeq.


Brucey(Posted 2014) [#244]
@Angros

Having a look at the source, I'm not sure why your MQ functions are using the heap so much for (temporary) Matrix instances.
There's more overhead to creating and deleting variables on the heap, than just using one on the stack. That and you need to ensure you are deleting the pointers at some later stage, something that is not an issue with scoped variables.


angros47(Posted 2014) [#245]
I ported MQ functions from warner version of MiniB3D: in the original version (written in BlitzMax) variables weren't even deleted (it was not needed, since BlitzMax has auto garbage collection). I ported the functions to C++, so I had to add the delete instructions; I also tried replacing them with variables allocated on the stack, but as far as I can recall (I did that port in 2010) when I compiled using all the optimizations the library was a bit smaller, and execution was slightly faster, using the current form. Why? I'm not sure: perhaps the code that allocates variables on the heap is easier to optimize (in-lining is simpler and so on); I don't know exactly how GCC optimization works, and what is the difference on assembly level.

I only know that, in current form, those functions work, so I don't want to touch them if I don't have to: of course, it's possible to change them to allocate variables on the stack (you only need to remove the "delete" and "new" instructions, and replace pointers with real variables), and it might even work better if compiled with no optimizations, but I doubt it will improve in any way the final result.


Krischan(Posted 2014) [#246]
I found a strange behaviour in my Blitzmax/MinGW installation. Remember: to make the OpenB3D mod work I copied all files from the MinGW\lib\gcc\mingw32\4.5.0\ folder manually to the Blitzmax\lib folder and overwrote all of them. Without that it crashed with these cryptic error messages. After that I recompiled all modules again.

Now, all my executables don't run without these two DLLs in the path or the same folder like the executable:

libstdc++-6.dll
libgcc_s_dw2-1.dll

And the executable is a little bit smaller than before (about 200K)

So I reverted everything back to my initial Blitzmax 1.50 + MinGW 4.5.0 installation. The compiled executable is now again slightly bigger and works without these DLLs (I renamed the MinGW folder before the start so that no DLL is found anymore).

It looks like these two DLLs or parts of them are not compiled into the executable when I copy the files to the Blitzmax lib folder - which seems to be necessary to get OpenB3D running, argh. Well, that's not acceptable, the executables should run without external DLLs. So what is wrong here? I tried different MinGW versions and it is always the same situation.

My AR/LD Versions are both 2.20.51.20100613, FASM is 1.70.03.


Derron(Posted 2014) [#247]
You have to copy AR/LD from MinGW to BlitzMax/bin too.

Each time you change MinGW:
- copy MinGW libs which exist in the BlitzMax libs folder
- copy MinGW ld.exe/ar.exe to the BlitzMax bin folder
- recompile all modules

Maybe you missed one of the steps


bye
Ron


Brucey(Posted 2014) [#248]
It's nothing to do with AR/LD.

Assuming your MinGW is meant to compile in static versions of these libraries, you may want to look in the lib directories for two .a files which have a name like libstdc++-6.dll.a (or something similar with the text "dll" and a ".a" suffix), and either rename them to something completely different, or remove them completely.
Then rebuild everything.

I've noticed that, for some reason, the correct static library is not always being picked up at build time, so instead it uses the "dll" version of the library, causing the executable to require the dll to be supplied.

Which doesn't make too much sense, because the build might say something like "-lstdc++-6" which should load "libstdc++-6.a" but it's actually loading "libstdc++-6.dll.a".


Unfortunately, it makes setting up MinGW, again, more hassle than it should be.
The setup scripts should probably now try to take this into account, and just remove those pesky files, allowing the problem to disappear.

meh...


Krischan(Posted 2014) [#249]
Brucey, following exactly your MinGW installation instructions the problem still exists. And when I rename or delete these two .a files and rebuild all modules I'm getting compile errors even in vanilla miniB3D. Thats frustrating.


markcw(Posted 2014) [#250]
Krischan, all I can suggest is make sure the environment variables MINGW and PATH are correct and any other MinGW paths are removed so your not using the wrong version. The MaxIDE about window should tell what it's using. Also, please post the errors you get.


Krischan(Posted 2014) [#251]
Ok its working now. One shouldn't install it over an existing Blitzmax installation :-D Using a clean Blitzmax 1.50 setup it worked, looks like there were some remnants in the Blitzmax lib folder which leaded to the missing DLL result.

However there is a different problem I found in my small demo. When you move and point the camera in a certain direction the complete alpha information is lost (press SPACE for some action and move with WASD):

See yourself: OpenB3D_Milkyway2.zip

Here you see the same direction and with a very slight move to the right the alpha information is suddenly lost until you turn back, what could be the reason?






Krischan(Posted 2014) [#252]
Hmm it has something to do with the BeginMax2D/EndMax2D part, uncommenting it only lets the skycube with the background stars switch brightness. And this brightness switching disappears when I comment the shadow part.

And in all cases this only happens when the sun/earth/moon objects are not in the camera frustum anymore. Very strange, is it a bug? or two?

So this code works now, without Max2D and shadows:


EDIT: oh, and I found a third bug - it looks the moon is very shy in OpenB3D - when I'm very close to it, it completely disappears suddenly - but the earth stays at very close distance. Changing the camerarange does not help. Scaling the moon to earth's size (1.0) helps.

Very, very strange.


markcw(Posted 2014) [#253]
Krischan, glad you got MinGW working! Did you copy all the libs across manually again?

I couldn't really see this brightness switching of the stars. I actually seemed to have no stars but it was due to "ScaleTexture StarsTexture" having subzero values which was shrinking them down.

I did find what was causing the alpha bug though. When I put "glBlendFunc(GL_SRC_ALPHA,GL_ONE)" (which is the Add blend mode) before RenderWorld it fixed it. So I now have a working fix to mesh.cpp where calling glBlendFunc happens all the time instead of only when the blend statement is true.

I can't reproduce the sun disappearing except when I'm as close as I can get to it and I pass through it.


Krischan(Posted 2014) [#254]
No, I didn't copy them manually. In my Blitzmax folder, I've deleted the lib folder and installed 1.50 over everything again. Then I installed MinGW (tdm-gcc-4.7.1-2.exe), then I ran Bruceys script. And then it worked.

Your OpenGL command before Renderworld worked here too, I'm glad you could fix that. What's the reason of the Scaletexture issue? In miniB3D I could scale textures below 1.0? Well, that's not really a problem as I'm planning to create the background stars in a different way than with a cube right now but it should be investigated.

And it's not the sun which disappears, it's the moon, see yourself: these two screenshots are made from nearly the same position - I've just moved a bit away forward, and I'm far enough away that no clipping should occur but it does. The only difference is that the moon is 0.25 size while the earth is 1.0. In tests I found out that if the distance between camera and moon is below 0.66666666 - the moon vanishes. And that's a strange value.





markcw(Posted 2014) [#255]
Re: ScaleTexture, the problem is my screen is quite small (laptop) and your scaling code only works well for a large screen width ie. 0.5 * (ScreenWidth / 2560). So the stars vanish.

Yes, I can see the moon disappearing before it should. It doesn't happen in minib3d. It seems the camera still thinks the moon is it's original size. I tried MeshCullRadius, ScaleMesh, FitMesh and CopyMesh and it still happens.


angros47(Posted 2014) [#256]
@Brucey

I've just tried changing allocation of matrices: the executable is a few bytes bigger, but much faster; likely, last time my mistake was to return a matrix from GetMatrix and GetInvMatrix (it had to be copied, slowing down everything).


Brucey(Posted 2014) [#257]
...a few bytes bigger, but much faster...

That's great! :-)


Brucey(Posted 2014) [#258]
... talking of OpenGL ES (in)compatibility... ;-)

Here's a small list of some of the things that are not available under OpenGL ES 2.0 :

GL_PROJECTION_MATRIX
GL_MODELVIEW_MATRIX
glFogf
GL_FOG
GL_FOG_MODE
GL_FOG_START
glFrustum
glLoadIdentity
glOrtho

I would be really nice to see this library running on all those many other platforms one day :o)


angros47(Posted 2014) [#259]
Without glLoadIdentity, the only way to load a matrix (that is needed to move/scale/rotate everything) is to use shaders. But shaders are not supported in GLES 1.0, so a version of OpenB3D based only on shader would not be compatible with Gles 1, and with opengl on older/poorly supported video cards.

So, I see only two alternatives: building two version (I don't like that idea: Minib3d is already too fragmented, I don't want the same to happen to OpenB3D), or adding a module to implement missing commands on GLES 2.0, too.


Derron(Posted 2014) [#260]
As you could do
?android
Bla
?not android
blubb
?

And it just skips the ?android-part on vanilla-blitzmax...couldnt you wrap the parts using "non-egl"-code into functions...and then use conditionals to use either the new or the old approach?

Or even better: provide both ways of doing things (like a renderpath). Then just setup overrideable defaults regardingly (like dx on windows and gl on other OS).
...maybe this is similar to what you suggested in option two...and I just did not get it.

Bye
Ron


markcw(Posted 2014) [#261]
Krischan, I found a workaround for the moon disappearing which gets it working as well as minib3d. This seems to happen to objects smaller than 1 meter. To fix it use:
ScaleMesh moon, 0.25, 0.25, 0.25
MeshCullRadius moon, 1.0

Note that ScaleEntity does not work and MeshCullRadius must be 1 or more. Then to get as close as possible I ended up with camera near as:
CameraRange cam, 0.001, 10000.0


Ferret(Posted 2015) [#262]
If i filled a octree with blocks using the same mesh, can i interact with a single block?
I want to remove or color a single block, is this posible?


angros47(Posted 2015) [#263]
To remove a single block, just use OctreeBlock with the same coordinates and level, putting 0 instead of the mesh handler.

Or you can provide the handler of another mesh, to replace a block with another.


feeble1(Posted 2015) [#264]
Is there a way to select which light is causing the shadows?


angros47(Posted 2015) [#265]
All lights cause a shadow.