Graphics

Reply

plot pixels on a 2D texture file

How can i create a custom texture file ? basically what i need is this :

 

 

byte vbuffer[256*256];

// plot a pixel
vbuffer[y * 256 + x] = Rgba(255,255,0,0);

 

 

and then move that into a texture 2d :

 

texture.setPixels(0,vbuffer);

 

 

 

 

Thanks for the help in advance!

Please use plain text.

Level 3

Level 3
liquidwater91
Posts: 120
Registered: ‎20-04-2012
Message 2 of 9 (339 Views)

Re: plot pixels on a 2D texture file

[ Edited ]

here's what i did to get it working:


[code]
uint[] vBuffer = new uint[256*256];
//Fill buffer to red
for(int i=0;i<256*256;i++) vBuffer[i] = 0xFF0000FF;
//Creature a RGBA texture.
Texture2D texture= new Texture2D(256, 256, false, PixelFormat.Rgba);
texture.SetPixels(0, vBuffer);
[/code]

 

edit: also, how exactly did u add the code tag?

Please use plain text.

Re: plot pixels on a 2D texture file

I'm already very thankful for the answer (it totally solves my problem).

 

But to make my life a bit easier; is there a easy way to convert a Rgba type to byte ?

 

Please use plain text.

Level 3

Level 3
liquidwater91
Posts: 120
Registered: ‎20-04-2012
Message 4 of 9 (329 Views)

Re: plot pixels on a 2D texture file

Rgba requires 32 bit's per each pixel, and a byte is only 8 bit's

 

for your implementation to work, you'd have to do:

 

[code]

byte[] vBuffer = new byte[16*16*4];
for(int i=0;i<16*16*4;i+=4){
    vBuffer[i+0] = 0xFF;  //Red
    vBuffer[i+1] = 0x0;    //Green
    vBuffer[i+2] = 0x0;    //Blue
    vBuffer[i+3] = 0xFF; //Alpha
}
Texture2D texture= new Texture2D(16, 16, false, PixelFormat.Rgba);
texture.SetPixels(0, vBuffer);

[/code]

Please use plain text.

Re: plot pixels on a 2D texture file

yes, i know. I just thought if there was a easy way convert rgba to  0xFF0000FF would be easier :smileywink:

 

 

but thanks a million anyway, it totally solves my problems!

Please use plain text.

Level 3

Level 3
liquidwater91
Posts: 120
Registered: ‎20-04-2012
Message 6 of 9 (318 Views)

Re: plot pixels on a 2D texture file

[ Edited ]

ah, do you mean like so:

[code]
public static uint RGBA(byte r, byte g, byte b, byte a){
//Seems uploading to set pixels expect RGBA as ABGR
return (uint)((a<<24)|(b<<16)|(g<<8)|r);
}
uint[] vBuffer = new uint[16*16];
for(int i=0;i<16*16;i++) vBuffer[i] = RGBA (0,255,0,255);
Texture2D tex= new Texture2D(16, 16, false, PixelFormat.Rgba);
tex.SetPixels(0, vBuffer);
[/code]

 

edit: again, how exactly did you format your first post?

Please use plain text.

Re: plot pixels on a 2D texture file

[ Edited ]

liquidwater91, when you want to insert program code into the body of your reply, click on the 5th icon on the toolbar just above the textbox you type your reply in (looks like a clipboard with a "C" on it) and then insert your code into the popup.

 

Like this:

 

10 PRINT "HELLO"
20 GOTO 10

 

Please use plain text.

Level 3

Level 3
liquidwater91
Posts: 120
Registered: ‎20-04-2012
Message 8 of 9 (250 Views)

Re: plot pixels on a 2D texture file

ah, thanks mate, i was wondering what people were doing, i always use quick reply.
Please use plain text.

Level 2

Level 2
ProfessorOhki
Posts: 17
Registered: ‎19-04-2012
Message 9 of 9 (245 Views)

Re: plot pixels on a 2D texture file

[ Edited ]
 
Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。