Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / - DBPro Coding Challenges -

Author
Message
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Apr 2006 16:53
I completely understand now

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 4th Apr 2006 17:38
Cool - I really like your blurred circles example above.

You know what would be interesting... If you did a benchmark app that compared doing the 3x blur to an image using your memblock method to the built in blur effect on bitmaps.

Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 4th Apr 2006 18:20
How do I put all the channels into a DWORD? O.o I get how to put the color in (i think) but how/where does the alpha channel go?

FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 4th Apr 2006 18:39
It goes ARGB...

There are many ways... The way I do it (not necessarily the best ) is:


That takes the normal colour, AND masks it with a white colour thats had the bit shifted across... Thinking about it..... Does this work?


If you want to make a predefined colour, I find it easiest to use "HTML" colours, ie: 0xAARRGGBB (eg: 0x80FF0000 = half transparent red)

Any help?

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Apr 2006 22:02 Edited at: 6th Apr 2006 14:21
I think my code is still not very optimal. The edges will always be a bit blurred with black(because 3 or 5 pixels missing = black).

Would this mean that the center pixel takes over the rest of the percentage missing?

for example, the top-left corner would be:

the surrounding pixels have (8+8+4.5) 20.5%, so this means that the center pixel would take 79.5%.

and a normal left edge pixel would be:

the surrounding pixels take (8+8+8+4.5+4.5) 33% so the center pixel would take 67%.

Is this correct?

[EDIT] I'll have to completely rewrite this code. There are some problems with the color calculation. It works in some examples though, but not in all.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Apr 2006 22:04
You could also write the color into the memblock by each byte seperately.


write membloock byte 1, pos, blue
write membloock byte 1, pos+1, green
write membloock byte 1, pos+2, blue
write membloock byte 1, pos+3, alpha

Keep in mind when you do it this way, the order is not R G B A, but BGRA. (i think, check the tutorial to make sure)


Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 4th Apr 2006 23:08
@SvenB: The way around that border issue is to simply start from 1 pixel around the edge (if you're using a 3x3). If you use 5x5 then leave 2 pixels around the edge. Thing is - this makes the pixels stay "sharp" but thats better than fading to black

@Phaelax - that makes sense.. It all depends on if DBP is Little or Big Endian... I think.

Segan
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 5th Apr 2006 03:43 Edited at: 5th Apr 2006 03:44
Well, school has caught up to me, so I don't have time to code anything tonight, so I thought that I'd throw some ideas around for feedback.

My original idea was to create a program where colors "diffuse" accross the screen, and then add some kind of user interaction (like add more colour where the mouse is etc.)

I think Nick's little trick would work really well for this kind of thing. My problem: I want to be able to fire a function like this many times per second, and updating 600*480 pixels is a fairly long task. I have been cooking up these possible solutions over the week:


Solution 1: Just make the area which is being updated smaller.

Pros: Probably the easiest way to do this.

Cons: While this does provide a cool demo, it wouldn't be to good for any cool background for a game, simply because it's too small.


Solution 2: Only update 1 out of every, say, 10 pixels every frame.

Pros: Would definitely speed it up a ton.

Cons: May end up with a weird effect updating pixels at different times.

Fixes: Perhaps do the math for half in one frame, the math for the other half the next frame, then update everything in the third frame. Or, a "vector" type solution could be had where an array with the "change rate" of each pixel is saved. The change rate updates the pixels every round, and a tenth of the change rates are given new values mathimatically each round. I have a feeling that there are a lot of other possibilities here, so if you have input, please post it!



Solution 3:Somewhere in my memory, I remember a game called "mono" which was made by (I think) geecee3 which had a cool colourful background. I could try to research how it was done.

Pros: It definitely works!

Cons: Well, it involves research... And I'm not too sure if geecee3 ever actually told the world how it was done.


So, everyone, there's my rant. Any feedback? I have a feeling that someone here will know of a much more slick technique for speeding things up that will leave my ideas in the dust!
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 5th Apr 2006 04:09 Edited at: 5th Apr 2006 04:16
@Nicholas Thompson: Oooh I get it but what's the "0x" for? o.0

However, I don't get what the rgb(255,0,0) part is all about either.. and why use a || in this part here which reads (0x00FFFFFF || (alpha << 24))? I guess I don't realy get it

Would this make a half-transparent blue pixel?


or do I need this


If I need the second one, then that sucks



FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2006 11:10
They both do the same.

The '0x' bit tells DBP thats you're working in Hexadecimal, hence using the F's

You are right - that first snippet makes a semi transparent blue pixel. The second snippet doensn't work.

The '||' and '&&' are OR and AND bit operators (respectively). Do you know much about boolean algebra? If not - I can put up a quick tutorial.

The first way, using hex, is fast and usefull if you have a static and predefined colour (eg, you're heath bar is always going to be semi-transparent blue). The other way, using RGB provides a way of easily creating dynamic colours.

You know how RGB works (I assume). The part after takes a white pixel and uses the OR operator to combine in the 4th byte which is alpha. This provides a semi transparent white pixel. You then AND it with the origional colour. If you AND any byte with FF, you get the same output (eg, 7A && FF = 7A).

Hope this helps If you need anymore - lemme know.

Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 5th Apr 2006 20:24
Ok, that helps alot But now I have a problem making my image memblock.. o.0

This code just freezes:


it just displays a black screen, and I have to use Ctrl+Alt+Del to close it. o.O

FunkyStickmen: Battle of the Races (1%)
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 5th Apr 2006 20:37 Edited at: 5th Apr 2006 20:39
I don't know much about memblocks yet, so if I'm wrong, ignore this,
but here is what I see...



1) your 'write memblock dword' is writing dwords to sequencial bytes 1,2,3
2) your write memblock needs a file to be open
3) you had a typo 'write memblock dwrod 1,1,size'
4) I added the top 2 lines to show you, you need to offset the bytes more, because dwords are 4 bytes long.


Maybe this is not all of the source code...
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 5th Apr 2006 22:10 Edited at: 5th Apr 2006 22:12
Huzzah I got it working



Thnx for all your help guys.

FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2006 00:40
@ImageAll: Just a hint... Where you have your blue constant it is perfectly valid to use the color value as you have done, however its also valid (and more human readable) to express it as hex, such as:
#constant Blue 0xFF0000FF

The first FF is for alpha (in this case, its fully opaque) then you have 00 for red and green then FF for blue.

Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 01:52
DBP won't let me use hex values in data statements, nomatter how I do it o.O

FunkyStickmen: Battle of the Races (1%)
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 06:23 Edited at: 6th Apr 2006 06:25
Ok, I made a mesh from scratch using a memblock -- a triangular pyramid. But aparently it's only creating one face, being from verts 1, 2, and 3. It's not making any of them to 4. o.O



What's wrong here? Do I have to manually tell it to make faces there?

Also, why is the lighting going a little weird? o.0

FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2006 09:09
I think mesh's have to be made of triangles (ie 3 verts). A square is 2 triangles.

What are you trying for Hex values?

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 6th Apr 2006 13:45 Edited at: 6th Apr 2006 13:46
[edit]irrelevant post.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 6th Apr 2006 14:33 Edited at: 6th Apr 2006 14:33
Ok, a new update. Now the edges display correct. But sadly, the number of lines has been increased too...



Can you still read the message? (4 times blurred)


It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 17:53
Quote: "I think mesh's have to be made of triangles (ie 3 verts). A square is 2 triangles."


Thank you for reviewing the coordinates.



it's all supposed to be triangles, but it's not drawing the other 3 O.o

FunkyStickmen: Battle of the Races (1%)
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 6th Apr 2006 17:59
try setting cull off.

If you want to make them visible, change the vertex order.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 18:02 Edited at: 6th Apr 2006 18:46
If I didn't have cull off, then when running the code you would only see one side of the face that has been drawn. And I doubt changing the order would help -- I'll bet that it's only going to draw a face between the first three verts nomatter what..

t3h picky reads "Hello everyone!"

Edit: Now I have 12 verts, three for each face -- It works! But I wish I could just connect them o_O



FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2006 18:11
The order you write the vertex's does make a difference (clockwise or counterclockwise).

What way are the normals for the faces?

What happens of you make the object spin (maybe using the mouse so you can control where you look)?

Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 18:24 Edited at: 6th Apr 2006 18:27
The normals are 0.1 longer than all of the coords - so a vert at 15,-10,-15 would have the normal XYZ pos's set to 15.1,-10.1,-15.1

The other thing is that all but one combo of the verts would have faces that point outward - even with cull on it only shows 1.

Quote: "What happens of you make the object spin (maybe using the mouse so you can control where you look)?"


One thing I'll probably never get used to here, is when people don't run the code


FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2006 18:32
I dont run the code because I'm at work and my work machine has all the graphical prowess of an abacus.

Do you know what a Normal is?

Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 18:49
Quote: "I dont run the code because I'm at work and my work machine has all the graphical prowess of an abacus."


lol

Yes I know what a normal is 0uo it makes things....normal...? o.0 Well it makes the face render funny

code updated above to make it work

FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2006 19:07
A normal is the direction a face is "pointing"... So, for example, the desk your keyboard is on would have 1 rectangular face pointing upwards (hopefully ).. This means there will be 6 verts (yup, 6). Thats because there are 2 triangles, each with 3 verts. Every one of these verts will have a normal of 0,1,0 (X,Y,Z). If that face had normals of 0,-1,0 then your desk worktop would be dark, unless you have a light under your desk... This is because the engine would think the face is pointing in the opposite direction to what it really is.

The advantage of specifying normals to the vert rather than to each face is that if you have a terrain, for exameple, you can blend the joins of each polygon. This is how the terrain looks smooth rather than faceted (faceted = when you can see each polygon individually). The way the blending works is each vertex has a normal which is calculated based on the surrounding vertices that are "attached" to that point in space.

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 6th Apr 2006 20:59 Edited at: 6th Apr 2006 21:00
[edit] again, irrelevant post.

I have to read your replies better .

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 6th Apr 2006 21:57
Now I'm working on an entire robot model with code . It's going to be a miniboss from Descent, level 7 .



That's as far as I've gotten on the right arm . It's going to be just that arm, and then I'll work on the left, and then the main body . And then I'll limb them all to the body .

I should probably stop using .

FunkyStickmen: Battle of the Races (1%)
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 6th Apr 2006 22:13 Edited at: 6th Apr 2006 22:18
Ok, I decided to try something in 3D too. Here it is:



more like a demo. But it looks kinda nice...

[edit] use the command set camera fov and set it to a higher angle to get more colors.

@ImageAll

Try making a mirrorfunction for 3D. Double the amount of vertices in the memblock and copy them from one side to another.
It'll save a whole lot of work on the head and body.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Image All
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 7th Apr 2006 01:18 Edited at: 7th Apr 2006 21:07
Quote: "Try making a mirrorfunction for 3D. Double the amount of vertices in the memblock and copy them from one side to another."


That's what I was going to do for the arms but I was going to have all three parts -- Right arm, hull, left arm -- as separate memblocks so I could limb the arms to the hull.

Quote: "It'll save a whole lot of work on the head and body."


Head? What head?

But seriously, it's not going to have an actual head o_O

Here's the completed arm limb: (yay!)




FunkyStickmen: Battle of the Races (1%)
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 02:37
The vertices have to be written clockwise and every face has 3 points, so there's no sharing of vertices unfortunately.

When we said memblock challenge, I dunno why I thought only images.


BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 8th Apr 2006 03:23 Edited at: 8th Apr 2006 03:25
This is really just an Image Memblock challenge.
But, you can use these memblocks in either a 2D or 3D environment of your choice.

Manipulating Image memblocks is what I will be judging.
Applying special effects, cool manipulations, clever little tricks, etc. is what I'm looking for.

Extra points for making your memblock routines into transferable functions, so we can all use them, enjoy them, learn from them, and expand the code base for everyone to use.

I'm seeing some interesting ideas, I will submit a few also, keep up the good work!
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 03:24 Edited at: 8th Apr 2006 03:25
)(*&^@)^&#$*&*@# I hate this friggin error.

"Cannot read an image currently locked by system"

Anyways, here's a new memblock entry from me, memblock matrix. (nobody said i couldn't reuse my old codes)

Hold shift to run faster around the matrix, arrow keys/mouse move.




Oh, then why am I seeing so many memblock objects? I guess you can disregard this post.


Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 03:45
messing with image alpha, a spot light demo.




Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 03:53
image overlay. Click on the screen and the coordinates are translated to the image's "space". (top-right corner off screen equals top-right corner of image, regardless of dimensions) When you click, a smaller image will be pasted onto the other way. Think bullet holes in a wall.




Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 04:00
Same concept basically. Erase and draw onto the image. Erase the image and see whats moving behind.




Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 04:04
I'm entering this snippet on behalf of Kenmo, because I think it should be here. Him and me started memblock images about the same time, and after he told me about the library he was gonna make I stopped making new image functions.





BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 8th Apr 2006 09:55
@Phaelax - good routines basically, but a few issues...

-a spot light demo.
nice.

-Erase and draw onto the image routine.
error 'memblock position outside range at line 108'
when hitting space or shift key

also - 'division by zero at line 61'
when I click the mouse


-Erase the image and see whats moving behind.
Cool

But good work, keep it up!
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Apr 2006 14:12
Lol, Good things phaelax!

If you move too fast over the spotlight thing, it looks like some lights are pasted on the plain.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Apr 2006 14:44
Memblock power!



A decent fire code (this version is 128x128 to keep it fast)

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Apr 2006 19:05
f-f-f-fire!




Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Apr 2006 12:47


I was bored...

Oh, and the function for blurring images is pretty slow. It works for small area's if you want to use it real-time, but the fps decrease fast when you go bigger.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 10th Apr 2006 21:17
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Apr 2006 01:16
Quote: "Deadline: 2 weeks from today - Saturday 15th April. - 11:59 PM PST (California time)
"



Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 11th Apr 2006 01:38
cheers. I'm gonna make time to do an entry one evening this week. Been trying to find a decent webhost this weekend - I want a VPS server so I can put a few sites on it. Quite like the look of this. Pretty cheap too...

Coding Fodder
22
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 14th Apr 2006 23:45
rats I found this post with one day left. I do have a nice little library of bitmap functions I wrote a year ago. Most use memblocks others lock the buffer, some do both. I am not sure if I am clever enough to make neat effects though. I will have to try


Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Apr 2006 01:37
I'm gonna give this a go tonight... Damn its been a busy week!

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 15th Apr 2006 02:54 Edited at: 15th Apr 2006 14:21
We are frantically doing taxes here in the US, and Saturday night is the deadline, so I won't get to the judging until Sunday late in the day, here in the US.(actually I found out Monday is the deadline for our taxes, because April 15th landed on a Weekend)

Basically you will have all day Sunday to finish up your image memblock functions.

I will post the judging results some time Monday.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Apr 2006 18:51
Quote: "Monday is the deadline for our taxes"

I forgot all about that, oh man. Looks like I'll be busy tonight.


Login to post a reply

Server time is: 2026-07-08 18:09:33
Your offset time is: 2026-07-08 18:09:33