<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[GMan's Mods & Stuff — Modifying iTexture or IImage per pixel]]></title>
	<link rel="self" href="https://gprogs.com/extern.php?action=feed&amp;tid=444&amp;type=atom" />
	<updated>2011-06-17T12:42:28Z</updated>
	<generator>PunBB</generator>
	<id>https://gprogs.com/viewtopic.php?id=444</id>
		<entry>
			<title type="html"><![CDATA[Modifying iTexture or IImage per pixel]]></title>
			<link rel="alternate" href="https://gprogs.com/viewtopic.php?pid=1674#p1674" />
			<content type="html"><![CDATA[<p>Hi,</p><p>I&#039;ve trying to draw directly to screen for drawing antialiased 2d lines, the best way looks like directly drawing to a iTexture and the using MyDriver.Draw2dImage()... to get it on screen, however i&#039;ve tried the code below but it looks like it must be messing with the memory directly because i see it drawing other textures, switching between random textures and colors? (its messy code atm because i was try multiple things, Sorry). I don&#039;t realy have anywhere to upload the example pictures but i could email if you wanted to see the issues when using setpixel()?</p><div class="codebox"><pre><code>    Local Itex:IImage = Mydriver.createImageEmpty(3, _DIMENSION2DI(256, 256))
    Local Col:SColor = _SCOLOR(255, 255, 255, 255)
        
    Local Vect1:Vector2di = Vector2di.createFromVals(Startpos.getX(), Startpos.getY())
    Local Vect2:Vector2di = Vector2di.createFromVals(EndPos.getX(), EndPos.getY())
        
    Local Pos:Position2di = StartPos
    Local Ang:Double = Vect1.getAngleWith(Vect2)
    Local Dist:Double = Vect1.getDistanceFrom(Vect2)
        
    Local SinVal:Double = Sin(Ang)
    Local CosVal:Double = Cos(Ang)
        
    
        Local A:Int
        While A &lt; Dist
            A = A + 1
            Itex.setPixel(Pos.getX(), Pos.getY(), Col, False)
&#039;            
            Pos = _POSITION2DI(Pos.getX() + (SinVal * A), Pos.getY() + (CosVal * A))
        Wend

        Local Texy:ITexture = MyDriver.addTextureFromImage(&quot;Tex154679&quot;, Itex)
                
                &#039;same as Driver.Draw2dImage() but just includes alpha by default
        MyGUI.DrawFull2DImage(Texy, _POSITION2DI(50, 50))
        
        MyDriver.removeTexture(Texy)
        Itex.drop()</code></pre></div><p>otherwise i&#039;ve found this code which i think would be better anyway, but i don&#039;t know to use the texture.lock() function and how to access the data it provides through the byte ptr? if i could get help converting this for bmax that would be awesome <img src="https://gprogs.com/img/smilies/smile.png" width="15" height="15" alt="smile" /> </p><div class="codebox"><pre><code>video::ITexture* t = mesh-&gt;getMesh(0)-&gt;getMeshBuffer(0)-&gt;getMaterial().getTexture(0); 
   video::SColor c = video::SColor(0xFFFF0000); 
   int p = t-&gt;getPitch(); 
   video::ECOLOR_FORMAT f = t-&gt;getColorFormat(); 
   int z = video::IImage::getBitsPerPixelFromFormat(f) / 8; 
   int m = 0; // can be from 0 to 8 (for texture with size 256x256) 
   void* b = t-&gt;lock(false, m); 
   if (b) 
   { 
      for (int x = 0; x &lt; (256 &gt;&gt; m); x++) 
         for (int y = 0; y &lt; (256 &gt;&gt; m); y++) 
            c.getData((unsigned char*)b + y * (p / (1 &lt;&lt; m)) + x * z, f); 

      t-&gt;unlock(); 
   }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[fishy417]]></name>
				<uri>https://gprogs.com/profile.php?id=243</uri>
			</author>
			<updated>2011-06-17T12:42:28Z</updated>
			<id>https://gprogs.com/viewtopic.php?pid=1674#p1674</id>
		</entry>
</feed>
