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.

Newcomers AppGameKit Corner / Issue with results from CreateRenderImage() to create sprites got gui elements

Author
Message
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 6th Jul 2017 12:07
So I have started on making some functions to add some basic buttons, slider etc to projects, started off easy with the BUTTON but already hitting a snag creating the images=>sprites for it, the below code should create a sprite that is half as high and half as wide as the window but it doesn't, I can provide any value to width and height and it's always spits out a sprite that is wildly wrong dimension wise, the sprite also looks blurred so is it being scaled?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jul 2017 12:46
Render Images always use the device height and width, they do not take any notice of the virtual resolution or window size. So you have to convert the size using the ratio of virtual resolution to device resolution.

I cheat when making Render images. I set the virtual resolution to the device resolution, make my render image, then set it back.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 6th Jul 2017 13:11
Thanks for the suggestion but I don't quite follow, I was not using a virtual resolution. I went ahead and added SetVirtualResolution(1024,768) but that made no difference?!
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 6th Jul 2017 13:28



I believe this may be a better way. I do not understand using the render commands.
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 6th Jul 2017 18:36
Thanks Golelorn that seems to be fine for now, might hit issues if I ever need to create widgets on the fly but a tleast I can continue now and look at rendertoimage later.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 7th Jul 2017 11:13 Edited at: 9th Jul 2017 21:26
I often use memblocks for creating empty or simple colored images like health bars. The first 4 bytes of the memblock is desired image width, the next 4 bytes is desired height, the next 4 bytes is color depth (which is always 32 for now, so just set that to 32). So a header of 12 bytes. Each pixel is 4 bytes (R = 1 byte, G = 1 byte, B = 1 byte, Alpha = 1 byte). So when creating the memblock you calculate the size like this: 12 bytes (header) + (width * height * 4) <- (each pixel is R+G+B+A, so 4 bytes). I will attach some sample code.

Is this a bad way to do it, anyone? Is it too slow?



EDIT: This image created this way is filled with R=0, G=0, B=0, and most importantly Alpha = 0 (which makes this image created this way completely transparent).

EDIT 2: My suggestion is for replacing CreateRenderImage() command and not having the hassle with virtual resolution and device resolution.
13/0

Login to post a reply

Server time is: 2024-04-27 03:11:52
Your offset time is: 2024-04-27 03:11:52