Icare Posted August 13, 2010 Share Posted August 13, 2010 Hi, I would like to draw into a texture, how can I do ? thank Nicolas Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted August 14, 2010 Share Posted August 14, 2010 Probably the best way is to use OpenGL directly to draw into a Leadwerks buffer as it's a lot faster than the internal 2D drawing commands. See Using OpenGL for drawing Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Icare Posted August 14, 2010 Author Share Posted August 14, 2010 I found another way to do this, but there is something that I don't understand. I must save my new texture to see it. Look at my code Local sphere:TMesh = CreateSphere() PositionEntity sphere, [0.0, 0.0, 5.0] Local mat:TMaterial = LoadMaterial("abstract::plastic_green.mat") PaintEntity sphere, mat Local texture:TTexture = mat.GetTexture(0) Local pix:TPixmap = texture.GetPixels(0, 0) For Local I:Int = 0 To pix.Width - 1 For Local Ii:Int = 0 To pix.Height - 1 pix.WritePixel(I, Ii, RGBA(0, 0, 255, 1)) Next Next texture.SetPixels(pix) texture.save("c:\nicolasdds.dds") Quote Link to comment Share on other sites More sharing options...
Rick Posted August 14, 2010 Share Posted August 14, 2010 I think you can use a buffer. Gamelib does something like this for name tags over players heads. You might want to check that out because I seem to remember you not having to save it to disk in order to see your drawings. Quote Link to comment Share on other sites More sharing options...
Icare Posted August 14, 2010 Author Share Posted August 14, 2010 Thank, but have you got an exemple ? Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted August 14, 2010 Share Posted August 14, 2010 Thank, but have you got an exemple ? Yes, the one I gave you a link too above. It explains how you bind a texture to a buffer and draw too that. You can then just use the resulting texture in the buffer, no need to save unless you need to have a copy in file format for what ever reason. You can do just the same using LE commands directly but I think the 2D Drawing commands only work with the back buffer which is a bit more restrictive. You probably have easier access to OpenGL from BlitzMax too. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Icare Posted August 14, 2010 Author Share Posted August 14, 2010 I transcribe the exemple into blitzmax code, it doesn't show how to write in a texture that is Currently applied to an object, but how to use lw texture and manipulate it with opengl. I would simply put some white dots in a texture that is used on an object. I do not understand what is so complicated to need back through the opengl ... Quote Link to comment Share on other sites More sharing options...
Icare Posted August 14, 2010 Author Share Posted August 14, 2010 It's working now, we must generated the mipmap. But if someone have something more quickly to do this with out pass by a pixmap. With this we can see in real time the result on the object Local sphere:TMesh = CreateSphere() PositionEntity sphere, [0.0, 0.0, 5.0] Local mat:TMaterial = LoadMaterial("abstract::plastic_green.mat") PaintEntity sphere, mat Local texture:TTexture = mat.GetTexture(0) Local pix:TPixmap = texture.GetPixels(0, 0) For Local I:Int = 0 To pix.Width - 1 For Local Ii:Int = 0 To pix.Height - 1 pix.WritePixel(I, Ii, RGBA(0, 0, 255, 1)) Next Next texture.SetPixels(pix) texture.GenMipMaps() Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted August 15, 2010 Share Posted August 15, 2010 I do not understand what is so complicated to need back through the opengl ... Nothing lol. It was just an example of how to draw onto a texture in a buffer that happens to use OpenGL. It's easy to mix and match OpenGL so really not that complicated and, unlike BlitzMax, users of other languages don't have access to all the properties you do so was a more general solution. Good that you have a solution working that suits your needs Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Aily Posted September 13, 2010 Share Posted September 13, 2010 It's working now, we must generated the mipmap. But if someone have something more quickly to do this with out pass by a pixmap. With this we can see in real time the result on the object Local sphere:TMesh = CreateSphere() PositionEntity sphere, [0.0, 0.0, 5.0] Local mat:TMaterial = LoadMaterial("abstract::plastic_green.mat") PaintEntity sphere, mat Local texture:TTexture = mat.GetTexture(0) Local pix:TPixmap = texture.GetPixels(0, 0) For Local I:Int = 0 To pix.Width - 1 For Local Ii:Int = 0 To pix.Height - 1 pix.WritePixel(I, Ii, RGBA(0, 0, 255, 1)) Next Next texture.SetPixels(pix) texture.GenMipMaps() If you want to execute this "on the fly", it is will be very slow solution. I've been maked some texture paint tool some time ago, and in my case I used shader to do this. 1 - get texture. 2 - clone it 3 - set source texture buffer as drawing buffer. 4 - set clone texture as buffer, that you want to draw (DrawImage(GetColorBuffer(clone_texture),0,0)) 5 - set post effect shader that have x,y uniforms to set position of drawing pixel and color of it ... in shader you need to draw all source texture pixels, but calculate, if x and y of current drawind pixel is = x and y uniforms that you pass to shader, than draw color pixel. This is realy fast way to draw to texture, and if you want to do some texture editor, you can write your own "brush" code in this post shader. Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
AnniXa Posted August 17, 2011 Share Posted August 17, 2011 Probably the best way is to use OpenGL directly to draw into a Leadwerks buffer as it's a lot faster than the internal 2D drawing commands. See Using OpenGL for drawing sorry for reacitviating this old topic, i just would like to know where i can find this article yet, since its not aviable under that link anymore. since this site http://www.leadwerks.com/werkspace/page/Documentation/le2/_/command-reference/2d-drawing/ is also referending to that article. Quote Whuts wroong? Link to comment Share on other sites More sharing options...
macklebee Posted August 17, 2011 Share Posted August 17, 2011 http://www.leadwerks.com/werkspace/page/Documentation/LE2/tutorials/_/programming/cpp/using-opengl-for-drawing-r19 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
AnniXa Posted August 17, 2011 Share Posted August 17, 2011 http://www.leadwerks.com/werkspace/page/Documentation/LE2/tutorials/_/programming/cpp/using-opengl-for-drawing-r19 ty very much Quote Whuts wroong? Link to comment Share on other sites More sharing options...
Canardia Posted August 17, 2011 Share Posted August 17, 2011 Also the Guess A Number game tutorial shows how to render text, images and 3D graphics into a texture: http://www.leadwerks.com/werkspace/page/Documentation/LE2/tutorials/_/programming/cpp/guess-a-number-r78 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
VeTaL Posted August 17, 2011 Share Posted August 17, 2011 http://www.leadwerks.com/werkspace/topic/3440-leafaq/ Here are also lot of usefull stuf (for example, rendering video into texture, realtime mirror and so on) Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.