Recent

Poll

Vote: What's the best project of this year?

"ball" by raw
1 (3.7%)
"bgragraphics" by j-g (pocket watch)
2 (7.4%)
"duplo6" by bylaardt
7 (25.9%)
"glslideshow" by handoko
2 (7.4%)
"mariocronch" by ericktux
0 (0%)
"movingdots" by lainz
1 (3.7%)
"movingdotsgl" by lainz
0 (0%)
"relogio" by bylaardt
5 (18.5%)
"starsfieldshooter" by turrican
0 (0%)
"steampunkclock" by bylaardt
1 (3.7%)
"sudoku" by user137
5 (18.5%)
"furiouspaladin" by handoko
3 (11.1%)
"educrace" by lulu
0 (0%)

Total Members Voted: 26

Author Topic: Graphics Contest 2017, please vote now!  (Read 201060 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Graphics Contest 2017, please vote now!
« Reply #330 on: August 24, 2017, 10:33:28 am »
For the texture vertical problem, I remember Akira1364 ever said it is an issue of BGRABitmap on Linux:
http://forum.lazarus.freepascal.org/index.php/topic,35313.msg255460.html#msg255460

For the color issue, I used my own BGRAtoRGBA function. But I now use OpenGL to handle the BGRA texture:
Code: Pascal  [Select][+][-]
  1.   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.Width, Image.Height, 0,
  2.     GL_BGRA, GL_UNSIGNED_BYTE, Image.RawImage.Data);
You can see the parameter GL_RGBA and GL_BGRA
« Last Edit: August 24, 2017, 10:36:12 am by Handoko »

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Graphics Contest 2017, please vote now!
« Reply #331 on: August 24, 2017, 12:05:34 pm »
For the texture vertical problem, I remember Akira1364 ever said it is an issue of BGRABitmap on Linux:
http://forum.lazarus.freepascal.org/index.php/topic,35313.msg255460.html#msg255460

For the color issue, I used my own BGRAtoRGBA function. But I now use OpenGL to handle the BGRA texture:
Code: Pascal  [Select][+][-]
  1.   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.Width, Image.Height, 0,
  2.     GL_BGRA, GL_UNSIGNED_BYTE, Image.RawImage.Data);
You can see the parameter GL_RGBA and GL_BGRA

For colors, I follow your code and it work well ! :)

And for inverted sprites issue, before creating OpenGL texture, I added a compilation directive like:
Code: Pascal  [Select][+][-]
  1. function TTextureManager.InitFromBGRABitmap(aIma: TBGRABitmap ): PTexture;
  2. var temp, dup:TBGRABitmap;
  3. begin
  4.  dup := aIma.Duplicate as TBGRABitmap;
  5. {$IFNDEF WINDOWS}
  6.  dup.VerticalFlip;
  7. {$ENDIF}
  8. ...
  9.  

Here the new version
www.lulutech.fr/EducRace/EducRaceSrc.7z
wishing you a nice life

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Graphics Contest 2017, please vote now!
« Reply #332 on: August 24, 2017, 01:46:43 pm »
I found 2 bugs:

1. oglcSurfaceImplementation.inc line #2412 - Syntax Error
The compiler reports error on line #2412, actually the bug is on line #2406. You should move the "const" to inside the $IFDEF block. The correct code should be:
Code: Pascal  [Select][+][-]
  1.  {$IFDEF WINDOWS}
  2. const
  3.   FLIP_TEXCOORD : array[ 0..3 ] of TTextureCoordIndex = ( ( 0, 1, 2, 3 ), ( 1, 0, 3, 2 ), ( 3, 2, 1, 0 ), ( 2, 3, 0, 1 ) );//( ( 3, 2, 1, 0 ), ( 2, 3, 0, 1 ), ( 0, 1, 2, 3 ), ( 1, 0, 3, 2 ) );
  4.  {$ELSE}
  5.  
  6.  {$ENDIF}

2. oglcSurfaceImplementation.inc line #2455 - Identifier Not Found
For this one, I have no idea.

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Graphics Contest 2017, please vote now!
« Reply #333 on: August 24, 2017, 02:02:09 pm »
Oh, I'm sorry, reading your publication where you talk about Akira, I started a method to avoid the image of inverted sprites then I forgot my first idea and left to rewrite another part of my code ... :-[

Simply remove the IFDEF WINDOWS, ELSE and ENDIF lines and keep only
Code: Pascal  [Select][+][-]
  1. const
  2.   FLIP_TEXCOORD : array[ 0..3 ] of TTextureCoordIndex = ( ( 0, 1, 2, 3 ), ( 1, 0, 3, 2 ), ( 3, 2, 1, 0 ), ( 2, 3, 0, 1 ) );//( ( 3, 2, 1, 0 ), ( 2, 3, 0, 1 ), ( 0, 1, 2, 3 ), ( 1, 0, 3, 2 ) );
  3.  
« Last Edit: August 24, 2017, 03:37:25 pm by Lulu »
wishing you a nice life

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Graphics Contest 2017, please vote now!
« Reply #334 on: August 24, 2017, 09:41:38 pm »
@Handoko, I made some test with glSlideshow with PNG image


1) 1024x768 image : no problem, all work perfectly

2) same image resized to 4096x4096 : application crash. I commented
Code: Pascal  [Select][+][-]
  1. //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.Width, Image.Height, 0,
  2.     //GL_BGRA, GL_UNSIGNED_BYTE, Image.RawImage.Data);
in unit uniGraphics, line 290/291 -> Nothing is drawn of course, but application don't crash.

3) same image resized 4096x4096 : I uncommented lines above, then I commented lines 325/327 in unit frmMain
Code: Pascal  [Select][+][-]
  1.   // Resize the image if it's larger than screen size
  2. //  with Image.Picture.Bitmap do
  3. //    if (Width > Screen.Width) or (Height > Screen.Height) then
  4. //      gls_ScaleDown(Screen.Width, Screen.Height, Image.Picture.Bitmap);
  5.  
No crash and image is drawn and move according the transition selected, but it's slow due to 4096x4096 pixels image.

Maybe it's a relationship to the fact that video cards only accept texture sizes in power of 2? But I don't know if this is a rules for all cards or only some of them.

In the framework for educ'race game, i use the following function to compute the new size of an image to resize it in power of 2. I tryed it with the 4096x4096 png image and it work.
Code: Pascal  [Select][+][-]
  1. function TTextureManager.ValueOfNextPowerOfTwo(aValue: integer): integer;
  2. begin
  3.  Result :=1;
  4.  while ( power (2,Result)<aValue ) do inc ( Result );
  5.  Result := trunc(power (2,Result));
  6. end;
  7. ...
  8. dup := TBGRABitmap.Create('xxxxx.png');
  9. temp := TBGRABitmap.Create( ValueOfNextPowerOfTwo(dup.Width),ValueOfNextPowerOfTwo(dup.Height),BGRAPixelTransparent );
  10. temp.PutImage ( 0, 0, dup, dmSet);
  11. ...
  12.  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, temp.Width , temp.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp.Data );
  13.  
  14.  
Note, in glTexImage2D call I now use 'GL_BGRA' as you advised me :)
« Last Edit: August 25, 2017, 09:18:34 am by Lulu »
wishing you a nice life

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Graphics Contest 2017, please vote now!
« Reply #335 on: August 26, 2017, 03:02:09 am »
Finished up an initial attempt at merging the features from Handoko's latest version of glSlideShow into my modified take. See my original post for more details and a link to the new zip file:
https://forum.lazarus.freepascal.org/index.php/topic,35313.msg255447.html#msg255447
It includes pretty much everything except for the re-ordering/remove popup menu. I also added TSplitters so you can freely resize the TOpenGLControl within the form.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Graphics Contest 2017, please vote now!
« Reply #336 on: August 26, 2017, 02:31:49 pm »
Thanks Akira, that code will be very useful for me and others who want to learn OpenGL.

But I have problem compiling your code. It said it fails to find BGRABitmapTypes unit. I checked my Online Package Manager and I can see BGRABitmap dan BGRAControl installed.

What should I do next?

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Graphics Contest 2017, please vote now!
« Reply #337 on: August 26, 2017, 04:08:02 pm »
I have solved the BGRABitmapTypes issue. Because Akira1364 didn't provide the project information files, I copy from mine. But I forgot to add BGRABitmapPack as the project requirement.

But now, I get new error when compiling.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Graphics Contest 2017, please vote now!
« Reply #338 on: August 26, 2017, 09:18:52 pm »
Because Akira1364 didn't provide the project information files, I copy from mine.

I've only been including the two PAS files and the LFM as I thought it would be easier for people to just make a copy of their existing project folder and drop the three files into it (replacing the ones that are already there, obviously) and then simply add BGRABitmap to the requirements of the existing LPI. 

But now, I get new error when compiling.

Woops! I just forgot to take off the decimal places so that the TimerInterval variable will work as both an Int64 or a Double depending on the platform, and didn't notice as on Windows the code compiles fine since in that case it actually is a floating point type.

Extremely simple fix, literally all you need to do is remove the ".0" at the end of each line in the case statement..... I replaced the zip file again with this change, as well.
« Last Edit: August 28, 2017, 03:56:46 am by Akira1364 »

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Graphics Contest 2017, please vote now!
« Reply #339 on: August 28, 2017, 10:59:16 am »
@Akira: I learned some good things with your code, thanks ! :)
About converting image size in power of 2: Do you think it's not necessary ?
I found this link that discuss on this topic: https://www.khronos.org/opengl/wiki/NPOT_Texture
wishing you a nice life

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Graphics Contest 2017, please vote now!
« Reply #340 on: August 28, 2017, 05:15:34 pm »
@Akira: I learned some good things with your code, thanks ! :)

Cool! Good to hear.

About converting image size in power of 2: Do you think it's not necessary ?

Well, what it boils down to is that NPOT textures have been supported on all GPUs released since roughly mid-2004. So the only users it could possibly matter for in the first place are those running pre-2004 GPUs. Frankly I imagine that the number of people who fit into that demographic is likely close to zero nowadays.

That being said, the "distorted images" issue in Handoko's code was not actually related at all to NPOT textures (if it was, it wouldn't have affected you unless you're one of the people running very old hardware. It also happened no matter what, regardless of whether or not the texture was actually NPOT.) It was caused by the fact that he was resizing the actual TBitmap images based on the size of the screen, and not the size of the OpenGL viewport, and thus when he called "glCopyTexImage2D" with viewport coordinates the pixels being read only made up a small portion of the image.

As you noted yourself, once the section of the code that resized the TBitmap was commented out, everything worked fine because all resizing was then only being done "virtually", by scaling the current OpenGL matrix (which is the correct way to do things.)
« Last Edit: August 28, 2017, 09:03:39 pm by Akira1364 »

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Graphics Contest 2017, please vote now!
« Reply #341 on: August 28, 2017, 07:48:48 pm »
Thanks you again Akira for your clarifications. I feel I'm stuck on OpenGL knowledge of the last century !  :D
I will study your code more thoroughly
wishing you a nice life

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: Graphics Contest 2017, please vote now!
« Reply #342 on: September 03, 2017, 03:06:05 am »
Just uploaded a new copy of the zipfile for my version of glSlideShow... can be found in my original post, as always, which I'll link here again:
https://forum.lazarus.freepascal.org/index.php/topic,35313.msg255447.html#msg255447

It now has all of the same right-click popup-menu-based slide reordering and removal functionality that Handoko's last update did. More interestingly/importantly, I also implemented the ability to save and load your slide/transition lineups to and from file, which Handoko had said was an intended feature. This is accessed through a standard "File" menu at the top of the form. Apart from that, I reworked the way I implemented some of the transitions a little bit as I realized I had caused weird scaling problems in certain edge cases.

Would be interested to hear how it works for everyone! (Especially if you're on Linux... I did my best to write everything cross-platform, but have not actually ran the application on anything other than 64-bit Windows 10.)
« Last Edit: September 03, 2017, 03:08:46 am by Akira1364 »

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Graphics Contest 2017, please vote now!
« Reply #343 on: September 03, 2017, 03:30:47 am »
Thank you Akira. I saved the file and will learn it properly when I am not busy.

But I'm curious why you used TSplitter for the resizing, why no directly resize it on FormResize?

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Graphics Contest 2017, please vote now!
« Reply #344 on: September 03, 2017, 03:42:12 am »
Hi, well seems that the votes reached the limit of 27, that's a lot. So I locked the poll, and according to the number of votes I created the list of winners.

Winners:
1° "duplo6" by bylaardt
2° "relogio" by bylaardt and "sudoku" by user137
3° "furiouspaladin" by handoko

About the votes by forum message reply: I think each participant received his feedback in the comments.

 

TinyPortal © 2005-2018