View Full Version : something that could become a 3d-editor
ReneMiner
15-02-2013, 20:17
In the past I started some 3d-editor-environment all in one window, but there's nothing to edit yet. I copied it from my old computers harddrive to check out for some Sub in there and I won't use it furthermore. So it's just a snoop-in preview how it could look like.
Guess I'm starting all over again since it's some time ago...
If anyone needs an idea: have fun with it!
Petr Schreiber
15-02-2013, 20:34
This is pretty impressive Rene, the GUI looks good!
Petr
ReneMiner
16-02-2013, 04:44
Something else - had some idea just seconds before i fell asleep and had to jump up - switch the computer on and type that in. Won't open antoher thread now,
The program up there should display a texture on a sprite if one uses "Explorer" and browses some images-folder on his/her drives.
Now I would like to do similar but in some GUI with multiple windows. But I was wondering how I would display a texture-file-preview, or a small image of a mesh to load, or shape-tool where you can select cube,torus, pyramids and stuff to draw them in 3d - yeah I was wondering, how I would display all this in another than TBGL-Window because there is just one- so I thought that would just be like displaying an image in some picture-box or on the form,dialog, whatever. Now my thoughts were browsing a little bit that direction...
We know how to render to texture,
...and there's a way to get the bitmap-data from that texture somehow...?
Could this be a direction to think of how to use more than just one large or Main-TBGL-Window and use some Image/Static- or Button w/bmp-control-alike element that would display just a texture? Some reserved memory (the bitmap-space) of that control where TBGL can put the "picture" on demand?
Surely it won't have the speed and i fear that it's not backbuffered - except you have some great idea how to double-buffer the control and synchronize it to OS - and its probably very slow - but it's not meant to display fast changing pictures- so could display static previews of almost anything, maps in games or scenes - anything that can be rendered to a texture - doesn't even have to be in the same scene as in TBGL-Window if using 3d...
...now I can go sleep... good night :zzz:
Petr Schreiber
16-02-2013, 14:55
Hi Rene,
the one large TBGL window can have sub-sections defined using the viewports (TBGL_Viewport). Support for multiple TBGL windows is technically possible, but it won't happen soon.
You could use this routine to copy contents of TBGL window to canvas:
%GL_BGRA = &H080E1
%GL_PACK_ALIGNMENT = &H00D05
%GL_UNSIGNED_BYTE = &H01401
Declare Sub glFlush Lib "opengl32.dll" Alias "glFlush"
Declare Sub glPixelStorei Lib "opengl32.dll" Alias "glPixelStorei" (ByVal pname As DWord, ByVal param As Long)
Declare Sub glReadPixelsCustom Import "OPENGL32.DLL" Alias "glReadPixels" ( ByVal x As Long, ByVal y As Long, ByVal width As Long, ByVal height As Long, ByVal format As DWord, ByVal nType As DWord, ByVal nPixels As DWord )
Function RenderToCanvas(hWnd As DWord, ctrlID As DWord)
DWord nWidth, nHeight
Canvas_Attach(hWnd, ctrlID)
Canvas_BitmapGet(nWidth, nHeight)
String sBuffer = Repeat$(nWidth * nHeight * 4, $SPC)
glFlush()
glPixelStorei(%GL_PACK_ALIGNMENT, 1)
glReadPixelsCustom(0, 0, nWidth, nHeight, %GL_BGRA, %GL_UNSIGNED_BYTE, StrPtr(sBuffer))
Canvas_BitmapSet(sBuffer, nWidth, nHeight)
End Function
Petr
ReneMiner
16-02-2013, 18:48
thanx for this one.
Is it also possible to display just a TBGL_Texture from memory on the Canvas but not the actual TBGL_Window-Content?
Or would I have to swap the scenes?
Petr Schreiber
16-02-2013, 19:03
Hi,
yes, it is possible - call the function above once you draw the scene geometry, but without calling TBGL_DrawFrame. This way the screen of TBGL window will not be updated, but Canvas will be.
TBGL_ClearFrame
' -- Draw scene for canvas here
RenderToCanvas(hCanvas, 0) ' -- This will update Canvas
' -- Clear the buffers again
TBGL_ClearFrame
' -- Draw the scene for TBGL window
TBGL_DrawFrame ' -- This will update TBGL window
I just noticed the image in Canvas will be upside down, hehe. This is not that huge problem, because you could temporarily turn the camera in scene upside down, and the result will be oriented correctly.
With the power of GPU, this is faster than manually rearanging the image lines on CPU.
Petr
ReneMiner
17-02-2013, 12:45
nice technique though, now I have some more idea what possibilities are offered. The main concern was how to display a texture which the user applies to his mesh, so he can just point to the tU,tV-position on the texture. So I probably won't draw the texture inside 3d-Scene but on a 2d-sprite flat in front -
This will copy for example a part of the GUI like in my script above attached - onto a canvas and not just the 3d-content of the scene?
Then I can create my own "Callbacks" :onthequiet: (i.e. I have just to take care for mouse-input on canvas) - but there's still the unsolved problems about minimizing, I don't get it and those c++-microsoft-sites don't tell me nothing. Microsoft itself dropped all this anyway. Windows 8 is designed for touchscreen and even vb6.0 does not install properly any more. As a Windows 8 user you do not have access to your own hard-drive as you want. It protects them folders+files and does not give you access to clean up manually. User gets treated as a child that has no idea what it's doing. So maybe thinBasic could go it's own way also could invent it's own unique kind of UI - away from splitted GDI and DirectX or OpenGL. We could run a "TBUIGL"...
and just for interest:
Qs about the first script-part:
Don't I have to detach canvas before the function ends?
could I omit the Declare Sub glXYZ Lib "opengl32.dll"-lines if I use #INCLUDE "thinbasic_gl.inc" which I would use anyway? Or's that something different?
Why's that "Import" instead of "Lib" in the third declaration? Typo?
...
Would it be an idea to built-in this "Snapshot To Control"-method to TBGL?
(so TBGL handles the Y-negafication of the camera-direction also)
Petr Schreiber
17-02-2013, 13:33
Hi Rene,
whole lotta of questions, isn't it? I will try to answer them in order...
The main concern was how to display a texture which the user applies to his mesh, so he can just point to the tU,tV-position on the texture
To just preview the texture, I would draw the texture to canvas control. Canvas_BitmapRender allows you to paint image from disk there.
This will copy for example a part of the GUI like in my script above attached - onto a canvas and not just the 3d-content of the scene?
Well, its up to you, you can modify the function to copy just a part of the window. The first two parameters of glReadPixels are x, y base, and the other two are width, height of copied area.
Don't I have to detach canvas before the function ends?
Up to you, it is not mandatory. Canvas_Attach is just a state switch.
could I omit the Declare Sub glXYZ Lib "opengl32.dll"-lines if I use #INCLUDE "thinbasic_gl.inc" which I would use anyway? Or's that something different?
The reason why I did it this way is because I discovered mistake in my OpenGL headers, it will be fixed in ThinBASIC 1.9.3.0
Why's that "Import" instead of "Lib" in the third declaration? Typo?
Import is alias of Lib, you can use both. I don't know why did I use Import here, I could use Lib too.
Would it be an idea to built-in this "Snapshot To Control"-method to TBGL?
I will think about it, it would need to have more flexible syntax I think, to allow copy of just portion of screen and such... Could you please make a feature suggestion in TBGL area (http://www.thinbasic.com/community/project.php?projectid=3) so I don't forget about it?
Petr
ReneMiner
17-02-2013, 13:45
oops- was just editing when you already answered...
So about the current thinbasic_gl.inc: I can still use the one I have in the meantime? What functions or methods are buggy?
Edit: how about this >>> http://www.cegui.org.uk/wiki/index.php/Main_Page - could'nt that be some library...
additional link about the same stuff >>> http://sourceforge.net/projects/crayzedsgui/?source=directory
additional similar stuff >>> http://sourceforge.net/projects/my-gui/?source=directory
Petr Schreiber
17-02-2013, 17:17
Hi Rene,
the statements causing problems in 1.9.x series are those which had parameter defined as BYVAL x AS ANY -> It worked in older versions, but this syntax does not make any sense ;). Affected routines are:
glDrawElements, glDrawPixels, glGetTexImage, glIndexPointer, glInterleavedArrays, glNormalPointer, glReadPixels, glTexCoordPointer, glTexImage1D, glTexImage2D, glTexSubImage1D, glTexSubImage2D, glVertexPointer
It is an issue which has been in the headers since the beginning, but thanks to tolerant parser it was previously interpreted as BYVAL x AS DWORD. All these functions worked before ThinBASIC 1.9.x series (I used glGetTexImage in my article (http://www.thinbasic.com/community/content.php?31-Beyond-TBGL-Offscreen-rendering-why-and-how) for example).
The beta ThinBasic 1.9.3.0 will fix the headers so they will work as they should.
Petr
ReneMiner
02-03-2013, 18:25
It's the time I abandon another attempt.
The reasons:
I want to create a game in 3d.
But in order to program the game I imagine, I need some mesh-modelling-software that is as flexible as possible, so I can change meshes vertices and textures during runtimes. And I'm not interested in learning the use of such things as Blender nor 3dsMax since it will take me two years to study before I get something drawn on will.
Now my restrictions are, I would like to use the built-In m15-Format since TBGL has all functionalities built-in for them - but it lacks of some easy-to-use editor and the materials are not part of the m15-mesh. That missing material I could handle with some additional materials-file that apply to the layers, won't be the big problem though...
So I feel like somebody, who wants to use some images, but has to write a fully functional commercial quality drawing-software first, in order to create something that I can display on screen.
A look back at my DL-Tinker: it's already too complicated in handling - there's too many keys and commands to remember and it doesn't support textures nor materials. All the basic 3d-drawing-functions (except texturing/materials handling) I have already inside DL-Tinker-script, so I won't have to re-invent it all and I felt like creating a new mesh-editor that is very easy to operate even to beginners. The above posted attempt was to complicated too and I went back to use the full window/screen to create an easy mesh-editor.
How easy? Check out the attached download. Even a 6-year-old should be able to use it. Any user should instantly be able to create stuff in 3d without any further explanation.
So I started to write this one, but somehow I got the feeling I don't get any step forward and originally I have a game in mind- not an editor that takes 6 months or more until I can start drawing some meshes for the game that I want to create... passion is fading out currently...
The only things you need to control it, is your mouse + the shift-key to control the camera.
Alternatively you can use the keyboard...
There's no mesh-editing yet - just some sprite+2d-gui (which is still expandable with new controls) and some movement+positioning in 3d-Space.
Maybe someone get's the idea...
Edit: File removed. No good idea to use sprites and textured objects in 3d...