Jump to content

klepto2

Developers
  • Posts

    856
  • Joined

  • Last visited

Everything posted by klepto2

  1. File Name: Extensions for LE.Net (including Samples) File Submitter: klepto2 File Submitted: 23 Jul 2011 File Category: Tools This is an early stage of my Extensions for LE.NET. These Extensions are fully independent of LE.Net but integrate flawlessly. The first release contains 4 Samples and the library binaries. The OOP extension shows how i wll add a pseudo oop layer to LE.NET (Extension methods) More will come soon ( I have holyday for a few weeks and so i have a bit more time to maintain them). All required assemblies should be included, if you find something missing or an error please let me know. I hope this will together with the now official supported .Net headers will push the Leadwerks .Net community into a new era . Click here to download this file
  2. this is a shader bug i postet a short time before in the bugtracker. Open the shader.pak and edit the 'Mesh/mesh_diffuse_fullbright.frag' and remove the line which defines texture 2 so that the file looks like this: #define LW_DIFFUSE texture0 #define LW_FULLBRIGHT include "mesh.frag" Also you need to copy the dlls and AwesomiumProcess.exe from Awsomium SDK into your output folder. Once the official .NET part is finished i will release a full Package with working Samples.
  3. This is mainly reverse engineered, but i have access to the original dll code and the sceneloader code (thx Josh). The scenloading is completely based on the original LoadScene command. The Vegetation functions are mainly exported directly as they are already accesable in Blitzmax, but 2 functions are done by looking into the Terrain Editing code snippet Josh posted in this forum.
  4. File Name: Custom Engine Dll (2011-11-14) File Submitter: klepto2 File Submitted: 17 Jul 2011 File Updated: 14 Nov 2011 File Category: Tools A custom engine dll, with extra funtionality added to the standard engine.dll. A lot of new functions (currently 67) were added and more will come. Currently it just comes with the dll and the wrapper sources for Leadwerks.Net and LE.Net and a list of new functions. Blitzmax will follow as soon as i have cleared some things with Josh ( the sceneloader uses original source code and i have to clarify if i'm allowed to publish this part or if i provide it as an extra module without source) Demos and samples will follow. [update 2011-08-08] Updated the dll to match Leadwerks Engine 2.5 Add 4 new functions void SceneLoaderDoProgress(Sceneloader sceneloader) // Alters Progress manually (needed when you not use the Leadwerks Flip command (eg forms controls) void InitSingleInstanceSystem(string path) // initialises A temporay path for the single instance system string LoadSingleInstanceMesh(string cs,Entity parent) // Loads a mesh as a single instance (same mesh, but different materials are possible) void ClearSingleInstanceSystem(int cf= 1) // Deletes the tempory folder or cleans the folder The single instance system is very simple but effective. Keep in mind to use this only if you really need it as it can break up performance when used to much. [update 2011-09-02] Added 3 new Functions one for removing Vegetation from the terrain and one to get all World Stats (BatchesDrawn etc.) float GetWorldStat(TWorld world,int stat) values for stat = 0 to 12 { 0 : batchdrawtime 1 : batchesdrawn 2 : entitiesdrawn 3 : entityculltime 4 : entitydrawtime 5 : lightsdrawn 6 : meshdrawtime 7 : octreeupdatetime 8 : rendertime 9 : terraindrawtime 10: vegetationdrawtime 11: TerrainSectorsDrawn 12: ShadowsDrawn } RemoveVegetation(TTerrain terrain, int layer, float x, float z, float radius) TModel LoadSingleInstanceModel(string cs,Entity parent) Version 2.5.0.2: -Fixed Cubemapping -Changed Framework to recycle already used buffers, which speeds up mutisized Viewport rendering - Added a C# sample for cubemapping Version 2.5.1: Based On latest LE Update (fixed TPick, etc) Click here to download this file
  5. After a second thought I agree with the internal approach which seems to be proven standard for Wrappers. Ok, the different imports in LE.Net and Leadwerks.Net i understand, but i never said that we should split the pInvoke into seperate classes, you can just split them into seperate files, this way it may be easier to find the correct place where to find the place to add new functions or change existing ones. I will post a sample soon.
  6. Very nice ! Works like a charm here on my work PC with a GTS 240. A little information: if you're using Blitzmax, you don't need to distribute the engine.dll.
  7. I have voted for other. i mainly use Leadwerks.Net but what drives me nuts is that the actual dll commands are internal and you can't access them outside. (Which is disturbing if you need to add a yet not implemented feature). I believe Leadwerks.Net should use LE.Net so you can seperate the engine and Leadwerks.Net commands and we only have to maintain one project which is handlicng directly with the engine.dll. Also it might be easier to extend current functionality. Also maybe seperating the whole DllImport stuff into different files (based on there use, eg: Terrain, Entity, etc) may help to organise the whole project better. Maybe we can start a new trunk with a class and file layout prototype.
  8. to be honest, I don't have source access (apart from small snippets Josh helped me out to fix some sceneloading issues, thx Josh). Even if you don't have source acces but using Blitzmax combined with blide you have access to much lower level function of Leadwerks. And with this in mind i explored some of the "hidden" functions and added them to the dll.
  9. no, I have written my own sceneloader which is shown in the video. The vegetation functions are real engine functions. They are already integrated since Josh has added the new vegetation system but he never offically support them and so he never exposed them to the public. In short the vegetatio nare native inbuilt functions and no hack with temorary sbx files or the like.
  10. that is exactly the intention of implementing the funtionality into bmx and exporting it together with rest of LE in the engine.dll.
  11. Hi Folks, another small progress update I would like to share with you. While working on extending the exported functionality of the dll i have discussed with some people here in the forum and I came to the conclusion that just extending the dll and program advanced parts in .Net is not really the best for the community. While some extensions will work only for .Net at first (eg Awesomium, full XBOX360 Controller support) most extension will be programmed fully in Blitzmax and exposed through multiple include files for Blitzmax users and an extended engine.dll for all other users. eg I will convert my Sceneloader to Blitzmax and export the functions via dll. For those who haven't seen it yet: Sceneloading with accurate progress support (the 102% bug is already resolved ) Also I can already show you a temporary state of the reapidly growing function list which are already added to the dll: IntPtr CreateCubebuffer(Texture cubemap,Buffer cubemapbuffer) void ActivateCubeBufferFace(Cubebuffer cubebuffer,int face= 0) void DeactivateCubeBuffer(Cubebuffer cubebuffer) IntPtr CreateCubemap(int width,int height) int SetVegetationModel(Terrain terrain,string file,int Index= 0) int SetVegetationDensity(Terrain terrain,float density,int index= 0) float GetVegetationDensity(Terrain terrain,int index=0) int GetVegetationShadowMode(Terrain terrain,int index=0) int SetVegetationRandomTilt(Terrain terrain,float tilt,int index=0) float GetVegetationRandomTilt(Terrain terrain,int index=0) int SetVegetationRandomRotation(Terrain terrain,float rotation,int index=0) int GetVegetationRandomRotation(Terrain terrain,int index=0) int SetVegetationRandomScale(Terrain terrain,float scale,int index= 0) float GetVegetationRandomScale(Terrain terrain,int index=0) int SetVegetationLODDistance(Terrain terrain,float dist,int index=0) float GetVegetationLODDistance(Terrain terrain,int index=0) int SetVegetationViewRange(Terrain terrain,float Range,int index=0) float GetVegetationViewRange(Terrain terrain,int index=0) int SetVegetationAlignment(Terrain terrain,int Mode,int index=0) int GetVegetationAlignment(Terrain terrain,int index=0) int DistributeVegetation(Terrain terrain,int index=0,int aligntoslope=0) void DeleteVegetation(Terrain terrain,int index=0) void GenerateColorMap(Terrain terrain,int resolution) void SetLayerCollisionType(Terrain terrain,int layer,int _type) void SaveVegetation(Terrain terrain,string file,int Index) void LoadVegetation(Terrain terrain,string file,int Index) void AddVegetationInstance(Terrain terrain,float x,float z,int layer,float density,int randrotation,float randscale,int aligntonormal,float tilt) void SetTerrainBaseMap(Terrain terrain,Texture texture) int SetMaterialBlendMode(Material material,int mode) int GetMaterialBlendMode(Material material) int SetMaterialBumpScale(Material material,float Scale) float GetMaterialBumpScale(Material material) int SetMaterialCastShadows(Material material,int enabled) int GetMaterialCastShadows(Material material) int SetMaterialColorMask(Material material,int enabled) int GetMaterialColorMask(Material material) int SetMaterialCullFace(Material material,int enabled) int GetMaterialCullFace(Material material) int SetMaterialDepthMask(Material material,int enabled) int GetMaterialDepthMask(Material material) int SetMaterialDepthTest(Material material,int enabled) int GetMaterialDepthTest(Material material) int SetMaterialGloss(Material material,float gloss) float GetMaterialGloss(Material material) int SetMaterialInvisible(Material material,int enabled) int GetMaterialInvisible(Material material) int SetMaterialOverlay(Material material,int enabled) int GetMaterialOverlay(Material material) int SetMaterialSpecular(Material material,float specular) float GetMaterialSpecular(Material material) int SetMaterialStipple(Material material,int enabled) int GetMaterialStipple(Material material) int SetMaterialZsort(Material material,int enabled) int GetMaterialZsort(Material material) Total extensions: 54 A lot of functions will be added in the next days and i have a lot of ideas about additional helper functions and additions all Leadwerks user should benefit from. thx for reading klepto2
  12. Of course i can add this as well. I have already added the veg functions to the dll as I'm using this in C#, but before release i wanted to add some more functions which are maybe needed. The idea about the different dll names sounds practical and we should do this.
  13. I will write a short summary on how to use the vegetaion functions in blitzmax and also provide a new engine.dll extended with these functions soon. Note these functions are and will not be officially supported by Josh (as far as i know).
  14. The project can directly be included into your solution.
  15. https://awesomium.com/buy/
  16. Le.Net is located in the Asset Store: http://www.leadwerks.com/werkspace/files/file/185-lenet/ and Leadwerks.Net is located at assembla, details in this post: http://www.leadwerks.com/werkspace/topic/3300-leadwerksnet-wrapper/
  17. Hi, this is just a short blog to keep you informed. I have promised to upload a first version last weekend, but unfortunatly I wasn't able to do so. I'm currently working on a solution to provide the extended functionality to both .Net Wrappers (LE.Net and Leadwerks.Net) which is more difficult than i thought. I have already extended the engine.dll with some new functions which already work in both .Net Wrappers and i will hopefully be ready with a small package next week. So no worry about it, I'm still working on it. As a small cookie i have this: Nothing special you think, well maybe you're right, but the shown scene is not loaded via LoadScene not the vegetation is done via the Editor. The whole vegetation is done via code (new engine.dll functions, unoffically) At least I have a small poll to set my priority to the correct Wrapper (both will have the same functionality at the end, but i have to start with one) thx for reading.
  18. Here is the promised Sample (just a .cs file) and a first (Alpha stage) of 3 of my Leadwerks.Extensions Library. The input system maps the original Leadwerks functions into an eventbased system including missing up-commands. Leadwerks.Extensions.Alpha1.zip
  19. the webTexture needs to be the same size as the WebView and this part: if (m_webView.IsDirty() && !m_loading) { Rect r = m_webView.GetDirtyBounds(); RenderBuffer buffer = m_webView.Render(); UploadToTexture(buffer,r); } is important, otherwise the rect maybe undefined if the view isn't dirty, alternatively you can leave the rect out of the code and upload the whole renderbuffer to the texture. Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, webTexture.Width, webTexture.Height, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, Buffer.GetBuffer());
  20. To be honest, i have the same problem with directx It just was a matter of 2 minutes to get awesomium working with LE. Of course you need some knowledge about handling Leadwerks textures with raw opengl, but than it is really simple. public void Render() { if (m_webView.IsDirty() && !m_loading) { Rect r = m_webView.GetDirtyBounds(); RenderBuffer buffer = m_webView.Render(); UploadToTexture(buffer,r); } } private void UploadToTexture(RenderBuffer buffer, Rect rect) { LE.BindTexture(m_rendertarget); int size =buffer.GetRowspan() / LE.TextureWidth(m_rendertarget); int ptr = (int)buffer.GetBuffer() + (rect.x) * size + (rect.y) * buffer.GetRowspan(); Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, rect.x, rect.y,rect.width ,rect.height, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, (IntPtr)ptr); } As you see there is no real magic behind it
  21. hi, it was me who was contacting you. I'm currently working on some Extensions to the LE.Net Wrapper including a class which handle Awesomium. Some details can be found in my blog here: http://www.leadwerks.com/werkspace/blog/16/entry-672-extending-lenet/ And here is a newer screenshot which shows a small test app with interactive Awesomium on a cube. (Mouse and Keyboard input is working) Feel free to contact me via MSN/ICQ or Mail.
  22. Hi folks, here is a new relatively short entry to my blog introducing my current side project (which will be the base of my bigger secret project) which I will make public to the community. I'm calling this project "Leadwerks.Extensions". In detail it is a project which will extend the current LE.Net headers with a set of setalite assemblies which will contain and provide some additional functions to the .Net community. My goal is to release a first set of dlls this weekend containing at least 3 assemblies. 1. Leadwerks.Extensions.Common The basic assembly containing shared functions used by all other assemblies but also providing some helpful functions like enabling rawGL mode, additional engine.dll commands. 2. Leadwerks.Extensions.Drawing Providing a growing library of 2D funtionality like animated images, viewport and scissor commands, and a lot more 3. Leadwerks.Extensions.Awesomium A picture often says more than words I have a lot of ideas for upcoming extensions (GUI, AI, IK, GameManagement, etc.), but if you have ideas or wishes feel free to post them in the comments. thx for your attention and more details will follow this weekend.
  23. File Name: TAdvancedPick (Tpick with uv coordinates) File Submitter: klepto2 File Submitted: 09 Jun 2011 File Category: BlitzMax A small Type I have used in my own gui. It takes a TPick type and calcualtes the correct UVW coordinates. Click here to download this file
  24. Hi, I have started a small project called Leadwerks.Extensions. The goal is to provide some deeper functionality from Blitzmax to other languages (not Blitzmax commands directly, but eg missing commands from the provided dll. I have started a test dll which should made my realtime cubemap code available to all languages. Unfortuntly I become errors in the code itself. The function access itself works well, but in the buffer creation function i get access violation errors (protected memory) when using glGenFramebuffersEXT. Here is my current Blitzmax code: SuperStrict Framework leadwerks.ENGINE Const COMPILE_DLL:Int = True Private Function ObjectPointer:Byte Ptr(o:Object) If o=Null Return Null Local p:Byte Ptr p=o p:-8 Return p EndFunction Public Type TCubeBuffer Field texture:TTexture Field buffer:TBuffer Field rb:Int[1] Field fb:Int[1] Field sb:Int[1] Field db:Int[1] Function Create:TCubeBuffer(texture:TTexture,buffer:TBuffer) Local cb:TCubeBuffer = New TCubeBuffer Notify "Debug 1" cb.Texture = texture Notify "Debug 2" cb.Buffer = buffer Notify "Debug 3" cb._BuildBuffer() Notify "Debug 4" cb.Buffer.Framebuffer = cb.fb[0] Notify "Debug 5" cb.Buffer.colorbuffer[0] = texture Notify "Debug 6" Return cb End Function Method _BuildBuffer() Notify "Debug 3.1" Local w:Int = texture.reference._Width Notify "Debug 3.2" Local h:Int = texture.reference._Height Notify "Debug 3.3" glBindTexture(GL_TEXTURE_CUBE_MAP , texture.reference._index) Notify "Debug 3.4" glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_Y , 0 , GL_RGBA8 , w , h , 0 , GL_RGBA , GL_UNSIGNED_BYTE , Null glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE) ; glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MIN_FILTER , GL_LINEAR) ; Notify "Debug 3.5" glGenFramebuffersEXT(1 , fb ) Notify "Debug 3.5.1" glGenRenderbuffersEXT(1 , rb) Notify "Debug 3.5.2" glGenRenderbuffersEXT(1 , sb) Notify "Debug 3.6" glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , fb[0]) ; glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_CUBE_MAP , texture.reference._index, 0) ; Notify "Debug 3.7" glBindRenderbufferEXT(GL_RENDERBUFFER_EXT , rb[0]) ; glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24 ,W, H); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_RENDERBUFFER_EXT , rb[0]) Notify "Debug 3.8" glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , 0) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT , 0) ; End Method Method Set(cubeface:Int) SetBuffer(buffer) Select cubeface Case 0 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_X,texture.reference._index,0) Case 1 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,texture.reference._index,0) Case 2 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,texture.reference._index,0) Case 3 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,texture.reference._index,0) Case 4 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_Z,texture.reference._index,0) Case 5 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,texture.reference._index,0) End Select End Method Method Unset() glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , 0) End Method Method CheckFBOStatus:Int(index:Int = 0) Local status:Int = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) Select status Case GL_FRAMEBUFFER_COMPLETE_EXT Print index + ": FBO Complete" Case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT Print index + ": Incomplete attachment" Case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT Print index + ": Missing attachment" Case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT Print index + ": Incomplete dimensions" Case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT Print index + ": Incomplete formats" Case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT Print index + ": Incomplete draw buffer" Case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT Print index + ": Incomplete read buffer" Case GL_FRAMEBUFFER_UNSUPPORTED_EXT Print index + ": Framebufferobjects unsupported" EndSelect Return Status End Method End Type Function CubeBuffer_Create:TCubeBuffer(cubemap:TTexture , cubemapbuffer:TBuffer) "win32" If COMPILE_DLL Then GCEnter() Notify "Create_Start" If cubemap <> Null Then Notify "Cubemap valid" If cubemapbuffer <> Null Then Notify "cubemapbuffer valid" Local b:TCubebuffer = TCubeBuffer.Create(cubemap , cubemapbuffer) Notify "buffer created" Return b End Function Function CubeBuffer_ActivateFace(cubebuffer:TCubebuffer , face:Int = 0) "win32" If COMPILE_DLL Then GCEnter() cubebuffer.Set(face) End Function Function CubeBuffer_Deactivate(cubebuffer:TCubebuffer) "win32" If COMPILE_DLL Then GCEnter() cubebuffer.UnSet() End Function Function CreateCubemap:TTexture(width:Int , height:Int) "win32" If COMPILE_DLL Then GCEnter() Return Leadwerks.Engine.CreateCubemap(width , height) End Function I have added some debug notfiies to check where the error occurs. The same code called from Blitzmax works. Using it from C# it fails and throws the error in line 64. (glGenFramebuffersEXT(1 , fb ) ) The CreateCubemap command works well. Does anybody know what is causing this and maybe how to solve this issue? thx in advance
  25. Hi folks, while working on my other projects I have started to research why the cubemapping doesn't seem to work in Leadwerks in Realtime. I have debugged through the code ( I was using Blitzmax to have access to the full debug output and fields of textures and buffers) and found out that it seems you can't create a real Leadwerks buffer for Cubemaps, I have also investigated TylerH' s early approach after the CreateCubemap command was added and from my experience with miniB3D extended I came to the conclusion that something must be wrong in Joshs solution and handling for realtime cubemaps. In Tylers lua sample he creates 6 buffers for each side of the cubemap, which is not needed when using fbo (Framebuffer objects). With this in mind I have integrated my old fbo code from 'miniB3D extended' and stripped it down to just support cubemaps and fit it (maybe a bit messy) into the existing buffer system (no I have no source license). The first result was promising and so i was extending my sample to handle full cubemaps and i was amazed how fast the result was. This is the result: The real fps without recording is double as high as it is showing in the video. Here is my code: ' ==================================================================== ' This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard ' Written by Rimfrost Software ' http://www.rimfrost.com ' ==================================================================== SuperStrict Framework leadwerks.ENGINE Local world:TWorld Local gbuffer:TBuffer Local camera:TCamera Local mesh:TMesh Local light:TLight Local ground:TMesh Local material:TMaterial Local materialfloor:TMaterial 'GCSetMode(2) RegisterAbstractPath( "D:/LESDK232r5/" ) Graphics(800,600) world=CreateWorld() If Not world RuntimeError "Failed to create world." gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2) camera=CreateCamera() PositionEntity camera,[0.0,0.0,-4.0] material=LoadMaterial("abstract::cubemap.mat") materialfloor = LoadMaterial("abstract::cobblestones.mat") mesh = CreateSphere(32) ScaleEntity mesh,[2.0,2.0,2.0] PaintEntity mesh,material light=CreateDirectionalLight() RotateEntity light , [45.0 , 45.0 , 45.0] Local cubemap:TTexture = CreateCubemap(512 , 512) Local cubemapbuffer:TBuffer = CreateBuffer(512 , 512) SetColorBuffer(cubemapbuffer , cubemap , 0) Local cubebuffer:TCubeBuffer = TCubeBuffer.Create(cubemap,cubemapbuffer) SetMaterialTexture( material , cubemap , 0) Local p:TPivot = CreatePivot() Local sp:TMesh = CreateSphere(16,p) MoveEntity sp , [4.0 , 0.0 , 0.0] EntityColor sp,[1.0,0.0,0.0,1.0] Local p1:TPivot = CreatePivot() Local sp1:TMesh = CreateSphere(16,p1) MoveEntity sp1 , [4.0 , 0.0 , 0.0] EntityColor sp1,[0.0,1.0,0.0,1.0] Local p2:TPivot = CreatePivot() Local sp2:TMesh = CreateSphere(16,p2) MoveEntity sp2 , [4.0 , 0.0 , 0.0] EntityColor sp2,[0.0,0.0,1.0,1.0] Local skybox:TMEsh = CreateCube() ScaleMesh skybox , [4.0 , 4.0 , 4.0] FlipMesh skybox EntityShadowMode skybox,0 PaintEntity skybox,LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat") EntityColor skybox,[1.0,1.0,1.0,1.0] Local frame:Int = 0 Repeat TurnEntity p , [0.0 , AppSpeed() * .5 , 0.0] TurnEntity p1, [0.0,-AppSpeed()*.5,0.0] TurnEntity p2, [0.0,0.0,AppSpeed()*.5] If KeyHit(KEY_ESCAPE) Exit If AppTerminate() Exit UpdateAppTime() UpdateWorld(AppSpeed()) SetBuffer(cubemapbuffer) PositionEntity camera , [0.0 , 0.0 , 0.0] ScaleEntity camera,[1.0 , -1.0 , 1.0] HideEntity mesh Local stage:Int = frame Mod 6 If stage = 0 Then cubebuffer.Set(0) RotateEntity camera,[0.0 , -90.0 , 0.0] RenderWorld() Else If stage = 1 Then cubebuffer.Set(1) RotateEntity camera,[0.0 , 90.0 , 0.0] RenderWorld() Else If stage = 2 Then cubebuffer.Set(2) RotateEntity camera,[-90.0 , 0.0 , 0.0] RenderWorld() Else If stage = 3 Then cubebuffer.Set(3) RotateEntity camera,[90.0 , 0.0 , 0.0] RenderWorld() Else If stage = 4 Then cubebuffer.Set(4) RotateEntity camera,[0.0 , 0.0 , 0.0 ] RenderWorld() Else If stage = 5 Then cubebuffer.Set(5) RotateEntity camera,[0.0 , -180.0 , 0.0] RenderWorld() End If cubebuffer.UnSet() ScaleEntity camera,[1.0 , 1.0 , 1.0] RotateEntity camera,[0.0 , 0.0 , 0.0] PositionEntity camera , [0.0 , 0.0 , - 4.0] ShowEntity mesh SetBuffer(gbuffer) RenderWorld() SetBuffer(BackBuffer()) RenderLights(gbuffer) SetBlend BLEND_ALPHA DrawText(UPS(),0,0) SetBlend 0 Flip(0) frame:+1 GCCollect() Forever gbuffer=Null FreeEntity light GCCollect() End Type TCubeBuffer Field texture:TTexture Field buffer:TBuffer Field rb:Int[1] Field fb:Int[1] Field sb:Int[1] Field db:Int[1] Function Create:TCubeBuffer(texture:TTexture,buffer:TBuffer) Local cb:TCubeBuffer = New TCubeBuffer cb.Texture = texture cb.Buffer = buffer cb._BuildBuffer() cb.Buffer.Framebuffer = cb.fb[0] cb.Buffer.colorbuffer[0] = texture Return cb End Function Method _BuildBuffer() Local w:Int =texture.reference._Width Local h:Int = texture.reference._Height glBindTexture(GL_TEXTURE_CUBE_MAP , texture.reference._index) glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA8 ,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,Null glTexImage2D GL_TEXTURE_CUBE_MAP_NEGATIVE_Y , 0 , GL_RGBA8 , w , h , 0 , GL_RGBA , GL_UNSIGNED_BYTE , Null glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE) ; glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MIN_FILTER , GL_LINEAR) ; glGenFramebuffersEXT(1, fb ) glGenRenderbuffersEXT(1 , rb) glGenRenderbuffersEXT(1 , sb) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , fb[0]) ; glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_CUBE_MAP , texture.reference._index, 0) ; glBindRenderbufferEXT(GL_RENDERBUFFER_EXT , rb[0]) ; glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24 ,W, H); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_RENDERBUFFER_EXT , rb[0]) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , 0) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT , 0) ; End Method Method Set(cubeface:Int) 'glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , fb[0]) SetBuffer(buffer) Select cubeface Case 0 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_X,texture.reference._index,0) Case 1 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,texture.reference._index,0) Case 2 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,texture.reference._index,0) Case 3 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,texture.reference._index,0) Case 4 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_POSITIVE_Z,texture.reference._index,0) Case 5 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT ,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,texture.reference._index,0) End Select 'glgetError() End Method Method Unset() glBindFramebufferEXT(GL_FRAMEBUFFER_EXT , 0) End Method Method CheckFBOStatus:Int(index:Int = 0) Local status:Int = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) Select status Case GL_FRAMEBUFFER_COMPLETE_EXT Print index + ": FBO Complete" Case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT Print index + ": Incomplete attachment" Case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT Print index + ": Missing attachment" Case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT Print index + ": Incomplete dimensions" Case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT Print index + ": Incomplete formats" Case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT Print index + ": Incomplete draw buffer" Case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT Print index + ": Incomplete read buffer" Case GL_FRAMEBUFFER_UNSUPPORTED_EXT Print index + ": Framebufferobjects unsupported" EndSelect Return Status End Method End Type One downside is that currently I get INVALID_ENUM error in debug mode, but I have no idea why as it is thrown from engine itself. Also this is unfortunatly a Blitzmax only hack as it needs some access to some not provided fields. But maybe Josh can use this code to finally integrate proper support of realtime cubemapping into the engine. thx for reading klepto2
×
×
  • Create New...