Jump to content

how to draw into a texture ?


Icare
 Share

Recommended Posts

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

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

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")

Link to comment
Share on other sites

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.

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

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 ...

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

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 :lol:

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

  • 4 weeks later...

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.

"Better" is big enemy of "good"

Link to comment
Share on other sites

  • 11 months later...

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.

Whuts wroong?

Link to comment
Share on other sites

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

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...