Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by dr_panther. 05/18/24 11:01
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, dr_panther), 724 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Blitting multiple Bitmaps with transparent parts? [Re: WretchedSid] #376808
07/06/11 20:27
07/06/11 20:27
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
If you need real randomness on quantum level, you don't need advanced software or hardware, just read out the mic for a snap second, and convert the result into a number tongue.
Or the webcam.
Or the position and time the user clicked with the mouse.
Or total play time, or total time the user pressed left arrow.

Just be creative to get some real randomness laugh.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Blitting multiple Bitmaps with transparent parts? [Re: Joozey] #376821
07/06/11 20:54
07/06/11 20:54
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
On UNIX systems its fairy common to use noise generated by hardware drivers as entropy source.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Blitting multiple Bitmaps with transparent parts? [Re: WretchedSid] #385367
10/17/11 17:15
10/17/11 17:15
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
hi there again.. sry to push that up.. but i´ve a problem.. again.. sry


Problem: Adding BLACK Fields isn´t possible, it seems like just everything grey-white is recognized


What i´ve tried:
Creating a 128 pixel circle. Complete black with a fadeout into transparent. Added Alpha Channel and saved as 32Bit TGA including Alpha.
Running the code with that circle.. just creates a grey outlines (border of alpha channel to black).. nothing more..

When i tried to use a 150,150,150 (RGB) Background, the background isn´t made darker at the circle position.. but became brighter at the alpha border...

the actual code:
Click to reveal..

Code:
#include <acknex.h>
#include <d3d9.h>
#include <default.c>


BMAP* map;
BMAP* plain_tile = "plain001.tga";

var plaincount = 0;
var plainfilecount = 7;
var plainmax = 500;
var active   = 0;
int pixelcount = 0;
var position[3];
var groundsize = 2048;

STRING* wort = "BILDMENGE ANGEBEN\noder ESC um den Generator\nzu beenden:";
STRING* input = "   ";
STRING* bitmapname = "Plain";
STRING* bitmapnumb = "1";

FONT* arial = "Arial#15";

PANEL* viewer =
{
	pos_x = 5;
	pos_y = 5;
	layer = 10;
	alpha = 100;
	flags = SHOW | TRANSLUCENT;
}

PANEL* infos =
{
	pos_x = 730;
	pos_y = 50;
	layer = 99990;
	alpha = 100;
	digits(5, 5,  "INFOS:", arial, 1, 0);
	digits(5, 15, "^^^^^^", arial, 1, 0);
	digits(5, 25, "<> Bitmapcount = %.0f", arial, 1, plaincount);
	digits(132, 25, "/", arial, 1, 0);
	digits(140, 25, 4, arial, 1, plainmax);
	digits(5, 115, "PLAIN NAME:", arial, 1, 0);
	digits(5, 127, bitmapname, arial, 1,0);
	digits(5, 145, "PIXELS SET:", arial, 1, 0);
	digits(5, 157, 10, arial, 1,pixelcount);
	flags = SHOW | TRANSLUCENT;
}
PANEL* frames =
{
	pos_x = 0;
	pos_y = 0;
	layer = 1;
	alpha = 100;
	flags = SHOW | TRANSLUCENT;
}

TEXT* txt_input =
{
	pos_x = 735;
	pos_y = 95;
	layer = 99999;
	alpha = 100;
	font = arial;
	string(wort, input);
	flags = SHOW | TRANSLUCENT;
}


void vec_trunc(var *vec, var limit)
{
	vec[0] = minv(vec[0], limit);
	vec[1] = minv(vec[1], limit);
	vec[2] = minv(vec[2], limit);
}


function terrain_to_height(ENTITY* ent,BMAP* he_bmap,var altitude)
{
	VECTOR temp_vektor, pixel_size;
	COLOR pixel1_color;
	var format, pixel1,pixel_posx,pixel_posy,vertex_num,pic_size;
	pic_size=bmap_width(he_bmap);
	pixel_posy=0;
	while(pixel_posy<pic_size)
	{
		pixel_posx=0;
		while(pixel_posx<pic_size)
		{
			
			//convert pixel_pos to vector
			pixel_size.x=(ent.max_x-ent.min_x)/pic_size;
			pixel_size.y=(ent.max_y-ent.min_y)/pic_size;
			temp_vektor.x=((ent.x-ent.min_x)-(pixel_size.x*pixel_posx))-pixel_size.x/2;
			temp_vektor.y=((ent.y-ent.min_y)-(pixel_size.y*pixel_posy))-pixel_size.y/2;
			format = bmap_lock (he_bmap,0);
			pixel1 = pixel_for_bmap(he_bmap, pic_size-pixel_posx, pixel_posy);
			pixel_to_vec (pixel1_color, NULL, format, pixel1); 
			vertex_num = ent_nextvertex(ent,temp_vektor.x);
			CONTACT* kontak = ent_getvertex(ent,NULL,vertex_num); 
			if(kontak.z!=ent.z)//if position of vertex changed, set 0
			{
				kontak.z=ent.z;
				kontak.v=NULL;
			}
			if(kontak.z==ent.z)//if position of vertex not already changed
			{
				if (pixel1_color.blue>0) 
				{
					kontak.z+=0.1+(pixel1_color.blue*altitude);
					draw_point3d(vector(temp_vektor.x,temp_vektor.y,kontak.z),vector(0,255,0),100,50);
					kontak.v=NULL;
				}
				
			}
			ent_setvertex(ent,kontak,vertex_num);    
			bmap_unlock (he_bmap);
			pixel_posx+=1;
		}
		pixel_posy+=1;
		wait(1);
	}
	c_updatehull(ent,1);

}


void main()
{
	video_mode = 8;
	d3d_antialias = 9;
	wait(1);
	video_window(NULL, NULL, (2+16), "Heightmap Generator");
	vec_set(sky_color, vector(1,1,1));
	vec_set(screen_color, vector(1,1,1));
	level_load(NULL);
	wait(3);
	
	map = bmap_createblack(groundsize, groundsize, 32);
	bmap_fill(map, vector(50,50,50), 100);
	viewer.bmap = map;
	frames.bmap = bmap_createblack(726, 726, 24);
	bmap_fill(frames.bmap, vector(255,255,255), 100);
	if(groundsize >= 2048)
	{
		viewer.scale_x = 0.35;
		viewer.scale_y = 0.35;
	}
	
	plaincount = 0;
	
	var randompic = 1;
	var little_format;
	var big_format;
	var alphablend;
	var alphablend2;
	var temp[3];
	var temp2[3];
	var a = 0;
	var b = 0;
	
	map = bmap_createblack(groundsize, groundsize, 24);
	bmap_fill(map, vector(50,50,50), 100);
	viewer.bmap = map;
	
	while(1)
	{
		str_cpy(wort, "BILDMENGE ANGEBEN\noder ESC um den generator\nzu beenden:");
		str_cpy(input, "   ");
		inkey(input);
		while(inkey_active != 0)
		{wait(1);}
		
		if(str_cmpi(input, "esc"))
		{break;}
		
		str_cpy(wort, "GEWÄHLTE BILDMENGE:");
		plainmax = str_to_num(input);
		
		pixelcount = 0;
		plaincount = 0;
		
		bmap_fill(map, vector(0,0,0), 100);

		big_format = bmap_lock(map, 0);
		if(plainmax > 200)
		{
			plainmax = 200;
		}
		
		while(plainmax != 0 && plaincount < plainmax)
		{
			str_cpy(bitmapname, "Plain");
			str_cpy(bitmapnumb, "111");
			randompic = integer(random(plainfilecount)+1);
			if(randompic < 10){str_cat(bitmapname, "00");}
			else if(randompic < 100){str_cat(bitmapname, "0");}
			str_for_num(bitmapnumb, randompic);
			str_cat(bitmapname, bitmapnumb);
			str_cat(bitmapname, ".tga");
			plain_tile = bmap_create(bitmapname);
			
			position[0] = random(bmap_width(map));
			position[1] = random(bmap_width(map));
			position[2] = 0;

			little_format = bmap_lock(plain_tile, 0);
			for(a = 0; a<bmap_width(plain_tile); a++)
			{
				for(b = 0; b<bmap_height(plain_tile); b++)
				{
					if(position[0]+a >= bmap_width(map) || position[1]+b >= bmap_height(map)) continue;
					
					//read map pixel
					pixel_to_vec(temp, alphablend, big_format, pixel_for_bmap(map, position[0]+a, position[1]+b));
					//read feature pixel
					pixel_to_vec(temp2, alphablend2, little_format, pixel_for_bmap(plain_tile, a, b));
					
					//color mixing in 3 steps
					//1.multiply feature pixel's color with normalized alpha
					vec_scale(temp2, alphablend2/100);
					//2.add resulting color to the map pixel's color
					vec_add(temp, temp2); 
					//3.check that resulting vector components stay within 0-255 range
					vec_trunc(temp, 255);
					
					//write the resulting color to the map
					pixel_to_bmap(map, position[0]+a, position[1]+b, pixel_for_vec(temp, alphablend, big_format));
					pixelcount += 1;
				}
			}
			bmap_unlock(plain_tile);
			plaincount += 1;
		}
		wait(1);
		bmap_unlock(map);
		break;
	}
	
	
	bmap_save(map, "Terrain.tga");
	reset(viewer, SHOW);
	reset(infos, SHOW);
	reset(frames, SHOW);
	reset(txt_input, SHOW);
	ENTITY* terr = ent_createterrain(map, nullvector, 512, 512, 8);
	terrain_to_height(terr, map, 0.5);
	
	//	sys_exit("");
}




Last edited by Espér; 10/17/11 17:30.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Page 3 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1