Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  What type of rendering should I use?  (Read 7704 times)
0 Members and 1 Guest are viewing this topic.
Offline sci4me

Junior Devvie


Medals: 1



« Posted 2016-01-17 02:55:36 »

By type, I mean immediate mode vs display lists vs VBOs vs whatever else there is.

I am trying to get an intuition for what I should be doing and when.

So, for example, what if I am trying to render a reticle on my screen. That will NEVER change EVER. How should I render it?
Another example: I'm making a voxel game. Blocks change relative infrequently (in the scope of computer speeds...) so how should I render those? I know Minecraft has been using display lists (and recently added VBO support).

So what type of rendering should I use? Are there times where I should use different types of rendering?
Offline theagentd
« Reply #1 - Posted 2016-01-17 03:42:53 »

1. Use VBOs, preferably with shaders. Immediate mode and display lists are both deprecated and shouldn't be used.


2.
a) How you draw a simple reticle probably doesn't matter. You could place the reticle vertex data in VBO at game start and reuse it for the rest of the game.
b) For a voxel game, VBOs have big advantages. You should split up your voxel world into chunks. Whenever a voxel changes (is mined, blah blah) you regenerate the triangle mesh of the chunk and store it in a VBO. Then you can reuse it until it changes the next time again.

3. Everything nowadays is drawn with VBOs. To get any kind of vertex data to the GPU, you should be using VBOs. There are however tricks that can be used to reuse data for improved performance. For example, it is possible to use instancing to draw the same mesh hundreds of times with a single draw call, using shaders to place each instance at a different location/rotation/etc. Another trick is using geometry shaders to transform the geometry to minimize the CPU overhead and the amount of data that has to be sent to the GPU. For example, you can draw your reticle sprite as a point with only 1 vertex detailing the position, size and color of it, and then use a geometry shader to expand it to a quad with generated texture coordinates for each corner.

VBOs are not really a "type of rendering". VBOs are simply the most efficient and powerful way of both uploading dynamic data to the GPU every frame AND keeping reusable data indefinitely in video memory, and should always be used nowadays. What you do with the data (indexed vs non-indexed rendering, using different shaders, expanding geometry with geometry shaders, etc) is what can actually differ nowadays.

Myomyomyo.
Offline sci4me

Junior Devvie


Medals: 1



« Reply #2 - Posted 2016-01-17 03:51:50 »

Why are shaders preferred? I mean, at the moment I have no desire for any fancy rendering. I just want to draw some geometry with textures.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2016-01-17 05:07:22 »

Shaders are the only thing that actually exist. The fixed functionality pipeline doesn't exist anymore. It's all emulated by the driver using shaders if you use the fixed pipeline and it's - you guessed it - deprecated.

Myomyomyo.
Offline sci4me

Junior Devvie


Medals: 1



« Reply #4 - Posted 2016-01-17 05:20:42 »

Okay so, even if I want the simple functionality like I mentioned, I should use a shader of my own?
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #5 - Posted 2016-01-17 08:05:46 »

In short, yes.

There is (read: was) very little downside to using shaders (and at this point none) and like @theagentd said fixed function is deprecated, meaning there is no actual support for it (and apparently doesn't actually exist anymore, which is good to know) so it may even go away entirely in the next version or so. If you are seriously considering programming a game with openGL (or improving your skills in general) you'll want to use VBOs and Shaders. They are everywhere and the amount of time you spend fighting the fixed-function is not worthwhile.

Your time is better spent with the future.

Every village needs an idiot Cool
Offline KaiHH

JGO Kernel


Medals: 794



« Reply #6 - Posted 2016-01-17 08:50:24 »

I agree with @theagentd and @thedanisaur about that you should use shaders, but for different reasons.
You should use shaders in case you want your application to run on OpenGL ES (mobile devices) or WebGL (browser) now or in the future.
It is not because the fixed-function pipeline is bad or will be removed, which for the time being and for the foreseeable future will not be the case.
ISVs, or at least Nvidia, have no interest in removing it, because there are still a host of (professional) applications out there depending on it that don't have the luxury of being rewritten or ported to "modern" OpenGL.
ISVs don't want to get those people angry about discontinuing the support for OpenGL <= 2.1.
Saying that the fixed-function pipeline is deprecated also only is true in the context of OpenGL 3.0 and 3.1, where it is marked "deprecated" and in fact in the OpenGL 3.2 "core" profile it has been removed. But that does not mean you cannot use it anymore.
If you want to write an OpenGL application that targets OpenGL 1.5 or even just OpenGL 1.1 today, that is perfectly fine! You can do that. Even on OS X. Wink
Just be aware that if you do so, you can only use features in more "modern" OpenGL versions via extensions or via the OpenGL >= 3.2 "compatibility" profile which some driver vendors decided to implement (all but Apple on OS X). And if you want to let your application run on a mobile device with OpenGL ES or on the browser platform with WebGL (which is becoming increasingly popular these days), you have to rewrite it to use shaders.
If you want to develop a simple desktop/PC application with simple requirements and don't want to learn shaders, there is nothing stopping you from using the fixed-function pipeline.
Offline theagentd
« Reply #7 - Posted 2016-01-17 16:19:25 »

It is not because the fixed-function pipeline is bad or will be removed, which for the time being and for the foreseeable future will not be the case.
It really has been removed.

Yes, you can still use the fixed function pipeline with a Compatibility profile context, but in the Core profile you HAVE to use a shader. It's just not worth learning all the quirks of the fixed function pipeline (like glEnable(GL_TEXTURE_2D) *shudder*) anymore when you can do the same thing with less quirk and much more future usability and flexibility using shaders. Also, OpenGL 3+ with a compatibility profile can't be used on Macs. You need to use an OpenGL Core profile, so if you want to use anything above 2.1 on Macs you must forsake the fixed function pipeline.

It is however faster to get *something* rendered with the old deprecated functionality. If you have no interest in advanced graphics programming and just want to draw some simple textured surfaces, then you could go with the old functionality to save a bit of time.

Myomyomyo.
Offline SHC
« Reply #8 - Posted 2016-01-17 16:33:09 »

Do what @theagentd said, follow him. He is one of the OpenGL experts on this forum.

The future is the core profile, and if you are learning I would recommend to go with the OpenGL 3.x. I admit that it is easy to get something on the screen with deprecated immediate mode, and there are also several games and libraries using it, but they are slow.

To get some fun, I have implemented a class that provides a glBegin/glEnd like behavior but renders through glDrawArrays with VAO and VBOs. You might want to take a look of it - Batcher.java. A bit of warning, do use it only if you like (I'm not advertising the engine, if someone would point it out, just that class).

Offline KaiHH

JGO Kernel


Medals: 794



« Reply #9 - Posted 2016-01-17 16:33:53 »

Before responding on that quote you should've read on my posting to the end. Wink
I already layed out everything you said in your post. Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KaiHH

JGO Kernel


Medals: 794



« Reply #10 - Posted 2016-01-17 16:48:59 »

Anyways: Of course you should start learning shaders and modern OpenGL. I just wanted to get straight that the fixed-function pipeline is _still_ available. Cheesy

And I am just waiting for people to declare whole OpenGL "deprecated" once Vulkan comes out, saying "Vulkan is the future. You should totally and immediately only use Vulkan from now on."
Even though it would take like a thousand code lines to render even a single triangle with Vulkan.
And people will say "Yes, it's the way it is. And Vulkan is the way to go. And it has sooo many times better performance compared to OpenGL, with all its command buffers. And you can even do everything super-multithreaded and take care of every bit of allocated memory for yourself. And you have fine-grained control over the residency of resources on the GPU."
And people will cry tears and want to go back to OpenGL 1.1 when they first come into contact with Vulkan and realize that they get less done than before and need ten times the effort to do anything and have a hundred times more bugs/errors in their code. Cheesy
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2016-01-17 18:13:05 »

And that, kids, is why you should use a game-engine, not write one.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline theagentd
« Reply #12 - Posted 2016-01-18 01:54:23 »

Anyways: Of course you should start learning shaders and modern OpenGL. I just wanted to get straight that the fixed-function pipeline is _still_ available. Cheesy

And I am just waiting for people to declare whole OpenGL "deprecated" once Vulkan comes out, saying "Vulkan is the future. You should totally and immediately only use Vulkan from now on."
Even though it would take like a thousand code lines to render even a single triangle with Vulkan.
And people will say "Yes, it's the way it is. And Vulkan is the way to go. And it has sooo many times better performance compared to OpenGL, with all its command buffers. And you can even do everything super-multithreaded and take care of every bit of allocated memory for yourself. And you have fine-grained control over the residency of resources on the GPU."
And people will cry tears and want to go back to OpenGL 1.1 when they first come into contact with Vulkan and realize that they get less done than before and need ten times the effort to do anything and have a hundred times more bugs/errors in their code. Cheesy

Vulkan is far from a replacement to OpenGL. Vulkan is an alternative that trades complexity for CPU performance, and OpenGL will keep on getting updates and live on. I wouldn't recommend people who aren't seriously interested in graphics programming to dive into Vulkan, and I probably wouldn't people who were interested in actually releasing games to use it either, since you're limited to fairly new cards (OGL4+ Nvidia cards, but only the absolute latest AMD cards). It'll take a few years until Vulkan becomes a serious alternative for most people. That obviously won't stop me from diving straight into it out of pure curiosity.

Myomyomyo.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2016-01-18 06:44:52 »

I think KaiHHs point is exactly your point, but simply one level of abstraction higher:

Quote
Vulkan Shader-based rendering is far from a replacement to OpenGL the fixed-function-pipeline. It is an alternative that trades complexity for CPU performance, and OpenGL the fixed-function-pipeline will keep on getting updates and live on. I wouldn't recommend people who aren't seriously interested in graphics programming to dive into Vulkan shader-based rendering,

Just like fixed-function-pipelines piggybacks on shaders, so will OpenGL on Vulkan, eventually.

You can reiterate the above statement with increasing abstraction, until you arrive at libraries like Slick and LibGDX and engines like Unity, or (browser based) environments like Processing, to digital images, and finally to Polaroid. Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline nsigma
« Reply #14 - Posted 2016-01-18 10:37:33 »

or (browser based) environments like Processing,

nit-pick - Processing isn't a browser-based environment (although it can target JS in the same way libGDX can).

Otherwise .. good point!  Grin

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #15 - Posted 2016-01-18 17:19:45 »

The problem I have with this argument for openGL and Vulkan is that it's not that much harder to get a triangle on screen using shaders(and to do this properly I'd say shaders are even easier once you add textures and colors). The "hard work" ends up being compiling and linking the shader. Where as vulkan is literally a different mindset. Beginners will cry blood trying to get anything on screen vulkan without a substantial amount of thinking.

Every village needs an idiot Cool
Offline KaiHH

JGO Kernel


Medals: 794



« Reply #16 - Posted 2016-01-18 21:32:16 »

You are of course right with the aspect that doing more complex texturing and lighting can get done better with using shaders. I absolutely agree. No question about it.
But the problem lies in the definition of "easier."

I'd say that it is not exactly "easier" to do proper lighting and texturing using shader, it rather is for the first time at all finally possible to do that with shaders properly, which was not at all the case with the FFP and its horrible API when it comes to combine textures, because it was..., well..., "fixed" in functionality and only could do Gouraud.
And everything new on top of that was done with lots and lots of state in that huge state machine called the OpenGL context. That was horrible. Absolutely. The FFP was very limited. But easy when you did not need anything more complex.

Now the hard work with using shaders begins with that you need to comprehend shaders. How they work. What their execution model is.
How to connect the vertex specification stage of the OpenGL API to the input variables of a vertex shader. What uniform variables are and how they work. How to transform vertices in the vertex shader with matrices. It now becomes more apparent what coordinate systems are and how to transform from one to the other. You also need to know what interpolated variables are and how those variables get interpolated between the vertex and fragment stages. What a sampler2D is and that it correlates with a texture unit. Then, how to actually do proper lighting and shading? Then, how to connect the output variables of a fragment shader to the framebuffer attachments (okay glFragColor is pretty simple).

In short: You need to learn a whole lot new concepts that you didn't need to before, because now that simple glEnable(GL_TEXTURE_2D) and glColor3f() won't cut it anymore when wanting to draw a simple texture and have colors. No, now you even need to program in a new language (GLSL) and know about shading and lighting models. Whether learning all this is worthwhile has to be decided by everyone on their own.
For me personally of course it is, because I like learning it and playing around with it, really. But just because I like it, doesn't mean I should propose/advice it to others.

The FFP was simpler but in the end *of course* stiff and inflexible when wanting to get away from simple Gouraud shading with one diffuse texture and finally do Phong and whole lot of new areas of computing for the first time with shaders.
That fact just lies in the nature of every abstraction: Loss of flexibility and also oftentimes worse performance.

With the FFP you also did not get to know how things work in more detail, and everything was hidden behind a more or less awkward interface. But the question remains: Do you actually _need_ to know when developing a simple game? Do you _need_ to become a master of OpenGL just to draw a single textured and colored something? Do you need the potentially powerful toolset of OpenGL and shaders to render your game? And do we want to recommend new developers to go this route?

Those are the only questions at least I want that we ask everyone who asks about what rendering technique they should use for their Minecraft clones. Smiley

Hence also @Riven's advice to use a game engine or any other such good libraries that simplify the lifes of game developers a lot.
You get a deeper understanding of everything with shaders, yes, just like you will get a deeper understanding of OpenGL and about the hardware when using Vulkan.

Sorry, somehow I wanted to get that down. Wink
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #17 - Posted 2016-01-19 19:35:19 »

I wasn't going to post this, but I ignored the advice to learn shaders and hope to get others to not follow in my footsteps. I wasted a bunch of time fighting that beast. Am I better for it? I'm not so sure so...

TLDR: If you are doing anything non-trivial you should use shaders. If it's trivial enough for fixed function you're better off spending the time learning how to use an existing engine.

--------------------------------------------------

I still disagree, and you basically made my argument for me. If you are doing anything non-trivial, say for instance a cube world game, you should use shaders.

Quote
Now the hard work with using shaders begins with that you need to comprehend shaders. How they work. What their execution model is.
How to connect the vertex specification stage of the OpenGL API to the input variables of a vertex shader. What uniform variables are and how they work. You also need to know what interpolated variables are and how those variables get interpolated between the vertex and fragment stages. What a sampler2D is and that it correlates with a texture unit. Then, how to actually do proper lighting and shading? Then, how to connect the output variables of a fragment shader to the framebuffer attachments (okay glFragColor is pretty simple).
You have to learn similar, basically throwaway, knowledge for the fixed-function pipeline.

1  
How to transform vertices in the vertex shader with matrices. It now becomes more apparent what coordinate systems are and how to transform from one to the other.

Not if you actually learned anything using the fixed function pipeline.

Quote
Whether learning all this is worthwhile has to be decided by everyone on their own.
Then use an engine like Riven said.

Every village needs an idiot Cool
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (521 views)
2019-09-04 15:33:17

hadezbladez (5476 views)
2018-11-16 13:46:03

hadezbladez (2379 views)
2018-11-16 13:41:33

hadezbladez (5737 views)
2018-11-16 13:35:35

hadezbladez (1215 views)
2018-11-16 13:32:03

EgonOlsen (4657 views)
2018-06-10 19:43:48

EgonOlsen (5665 views)
2018-06-10 19:43:44

EgonOlsen (3192 views)
2018-06-10 19:43:20

DesertCoockie (4091 views)
2018-05-13 18:23:11

nelsongames (5030 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!