Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openworld2
#1
Hello!

I wanted to do an experiment. I tried realistic lighting effects. Sunlight, shadow, fog.I was curious about what would happen if I used opengl by preparing static elements and then not using any more complicated mathematical operations. Meaning that I would fill the 'space' for opengl and then not deal with anything else, just controlling the camera view. Like a 3d model viewer. So that I wouldn't have to sort data during rendering. I naively thought that this would make opengl 100% faster, reducing the communication time between the opengl programs. In principle, I thought that this would be able to handle hundreds of thousands of polygons, since opengl should be able to handle it on hardware.

But unfortunately it's not good. I've already created several 3d programs with the _maptriangle command, which always rendered smoothly. The more polygons were used, the more I had to gradually lower the image resolution. Here is opengl. I'm full of questions. Although I know opengl, I learned it in other development environments, but here in qb64 it has an unusual use. I'm full of questions that I don't understand. From the game of fellow forum member aadityap0901 Minecraft I grabbed the methods that are needed to use and embed opengl correctly. It was a great help, thank you very much! For example, I don't understand what calls 'SUB _GL'? What's the point of this if I don't control the drawing. What if I don't want to display it statically, but there are also animations? If I ignore the fact that it draws when it wants, the scenes and figures may slip. And if I exit subgl if the scene is not ready yet, then I will lose frames. It would make sense if I could trigger the rendering. '_display' has no effect.

This was one of the problems, and the other one is that _maptriangle works faster than opengl for me. With _maptriangle I could draw about 10000 triangles stably at 30fps. This opengl program thinks twice when there are more than 8000 triangles, and the fps drops to around 10. It could be that I'm missing something. It could be that my computer is outdated. I don't get an answer to these. The program writes out how many triangles it draws in a scene while it's running, and shows how many times SUBGL runs per second. It's interesting that it always writes out 60, even then it stutters. So it could be that my Windows system or my computer is at fault.

I'd like you to try it. It could be that it will run well on a faster computer. It could also be that it won't. And I'm messing something up.

Set mapresX, MapresY . This allows you to set the terrain resolution. It is currently set to 60x60, a 3600 square, which is 7200 triangles. Try it with 200x200, 300x300...

I would like to know how many triangles you can draw while maintaining a stable 60FPS.

'file_mapdeep' - you can enter any image. The terrain will be a grayscale version of that image. You can even use paint to draw roads and hills

I hope that fellow forum member aadityap0901 will have some ideas! Thanks for giving me feedback!

Reply
#2
Dang those clouds are nice! Are they images or generated by code?
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
(06-28-2025, 10:18 PM)bplus Wrote: Dang those clouds are nice! Are they images or generated by code?
The textures are simple images. The water surface is what the program generates. It is a projection of a hemisphere of the sky.

Have you tried increasing the map resolution? (mapresx,mapresy). Did the playback lag?
Reply
#4
I just watched your video, don't have time to dig into things for a copule of months but sure would like to do skies like in video if you are generating those.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#5
Hey MasterGy!

The title itself interests me - Openworld 2, the last time I saw it, was on AshishKingdom Github

I really dug deep into this code (especially _GL and the part where you generate arrays).

Pardon me for the language used here - it might sound harsh, but I am not used to speak in English...

Here are some of my suggestions:
1. Use Texture Atlas, rather than using _glBindTexture three times... that would make it just once, although you would need to recalculate your texcoords.
2. Don't use cos, sin, and non-static subroutines & functions (because it slows down the GL function).
3. You are using _GL_Cull_Face the wrong way! To use it, do this
Code: (Select All)
_glEnable _GL_CULL_FACE
_glCullFace _GL_BACK
_glDisable _GL_CULL_FACE
4. Don't do any heavy calculations in Sub _GL (like calculating ang2, ang1)
5. You might wanna use _glDrawArrays, because it is much faster than uploading an index array to the GPU every frame...
That's it.

I am impressed by the fog calculations; you must've really worked on that for long.
and I really liked the _glTranslate waterlevel idea. If you don't mind, I may implement it in my next QB-Blocks 5 (I thought to keep it a surprise).

On my laptop, I can render 179867 with 55 fps (x, y => 300)  Big Grin

And I like that water reflection. I like it's simple code too Big Grin
Reply
#6
(06-29-2025, 02:28 PM)bplus Wrote: I just watched your video, don't have time to dig into things for a copule of months but sure would like to do skies like in video if you are generating those.

Hi Bplus!
Editing the sky is easy. You can see what it looks like in the 'need' folder. The textures called 'sky' are drawn on the hemisphere that you see as the sky. Everything is set up so that the center of the texture will be the light source. This is important because it will rotate that way, and the light will seemingly come from that direction. Since the two ends of the texture touch each other in the X direction, the image must be edited so that the center end is symmetrical. That's all the requirements. You can put anything in. In the latest version, the general light, fog, shadow, and water base color are determined by a single color. And those are the averaged colors of the 'sky' texture. If the sky is a sunset, then all shades will be reddish.
Reply
#7
Hi aadityap0901 !

I was really waiting for your answer, because it's obvious from the Minecraft game that you're really into opengl. You're my guy! Smile

Basically, the problem with my program is that it generates XZY instead of XYZ. This is an initial idiocy. I didn't care about it, then I had to cloak it. That's why it has to be rotated. But this is a minor problem. It performs chaotic (and unnecessary) transformations to make it look good. The 'cullface' you mentioned is the key. It's a lifesaver. I know it, but I didn't use it properly. qb64 accepted an incorrect syntax, but it shouldn't be that way. It accepted the command, but didn't apply it. The syntax you wrote is the correct one! This is really necessary!

What I don't completely agree with is the omission of sin/cos and other mathematics in subgl. why? I did the opposite! I noticed that I don't control subgl. Some indecipherable internal thing controls it. If it can handle 60fps, it works at that. If it can't handle it, it works at 30fps. If it can't handle that either, it takes itself off. But the point is that it's a good reference. So, since the rendering timing is untraceable, what if we tied all physics/control to it? How could I be in sync with the drawing that I don't control? Then what if I put all other operations in SUB _GL! We would only leave this much for the internal cycle of qb64:

Do: _Limit 2000
If InKey$ = Chr$(27) Or _KeyDown(27) Then System
Loop

Not joking, but really! I rewrote the program, and the control starts from 'SUB _GL'. It measures how many times it runs itself. From this, a 'deltatime' can be calculated. A multiplier. This multiplier is given to every movement. So it doesn't matter what the frame/s is, the physics are constant and will adjust to the framerate. Moreover, the stuttering has stopped. If your computer has the performance you wrote, then unfortunately my computer is outdated.

The other idea, the map atlas. With many thousands of alternating bindings and drawarray instructions, the statement that it is slow is correct. OpenGL should not receive many short instructions. But I think rendering / 10-20 bindings is enough. It would not be reasonable to put everything in an atlas. It is advantageous for many thousands of repetitive operations, but in this case I don't think it matters much.



Reply
#8
I had an idea about the day time:
We could use color arrays for the water texture to give it the look we want depending on the time of the day.
It would enable different time of day, without reloading and changing style.
I use it in QB Blocks 4 for lighting, however I haven't used it in it's full potential.
Give it a try.

I looked into your and realised that in Sub fill_map_opengl_arrays:
Code: (Select All)
...
gl_map_vert(index + 0) = mapsizeX / (mapresX - 1) * ax
gl_map_vert(index + 1) = mapsizeY / (mapresY - 1) * ay
gl_map_vert(index + 2) = zmapdeep(ax, ay)
...
You are following the 2D cartesian coordinate system, but in 3D opengl it is different:
Code: (Select All)
X: horizontal (left(-ve) -> right(+ve))
Y: vertical (down(-ve) -> up(+ve))
Z: horizontal (out of screen(-ve) -> into screen(+ve)
Changing this should eliminate the use of gl_map_face array, maybe increase the framerate.
I tried but failed implementing this, because all this calculation is getting over my head Rolleyes
BTW, this is the first time I am reading some code deeply, which isn't mine Big Grin
Reply
#9
Yes, that's why I wrote above that I started writing the program with XZY instead of XYZ, and it stayed that way. That's why there's the unnecessary rotation.
I put the cullface in correctly, although I don't feel any speed.
But my computer is probably slow. Sad You wrote: "On my laptop, I can render 179867 with 55 fps (x, y => 300) " That's really good!!! Unfortunately for me, XY is maximum 150, and even then only 30fps. Sad It's really good that you tried different values!

I did what you said once a long time ago. Nights and days alternate. But then I didn't know opengl, and it was made with maptriangle.


https://qb64phoenix.com/forum/showthread.php?tid=1131
https://qb64phoenix.com/forum/showthread.php?tid=1062
Reply
#10
(06-30-2025, 09:26 AM)MasterGy Wrote: I did what you said once a long time ago. Nights and days alternate. But then I didn't know opengl, and it was made with maptriangle.


https://qb64phoenix.com/forum/showthread.php?tid=1131
https://qb64phoenix.com/forum/showthread.php?tid=1062
This is actually good, and I am wondering how you added fog with maptriangle. Will look into this code some time.

I guess your hardware is outdated, because on my laptop I get a boost by enabling _GL_CULL_FACE, I can now render MapSize of 300->320 with 56 fps.

Just saying, I encountered a bug in this:

[Image: 06302025194656.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)