r/GraphicsProgramming • • Feb 22 '24

Can someone explain me how you would draw a piramid?

I have never done any coding or graphics so some questions could be wrong. We have now 4 triangles and 1 quad.

  1. How do you draw it? Do you send vertex in order to the gpu and tell it to draw?

  2. I dont know if recent gpus do support quad rendering but most do break down to triangles? How do you determine the break down?

  3. The whole figure would be one color blob, so we need some basic "lighting"? Like adding a darker color to the sides and the front a more lighter color? There would be no 3d figure visible else.

  4. How do you draw the planes of the triangles? How do you know where to draw at all there?

  5. You would try to connect the vertexes to the neightbor, so that you have lines, but there is no infinite resolution, how do you determine where to place the pixel? Do you "mix" the pixel with the background? Like antialiasing?

  6. How do you do the perspective? the quads last two vertexes would be more next to each other and less far away?

  7. If you decide to rotate it, how do you compute the positions of all vertexes?

  8. If you have a windows where you can press down your mouse to rotate the figure, you wouldnt redone the vertex again and again? How do you store the matrix? On rotation, the side that was before on the back could now be the front, so lighter color? And all lines and perspectives have to be redone? The planes have to be redrawn? Sounds like a lot of work.

  9. You could also add a texture, some texture parts could be reused on multiple sides, how do you determine what position and coords on the texture?

  10. How do you store the texture?

  11. Wouldnt the texture get stretched if the figure side is bigger than the texture?

  12. What part do you save after rotation? The more you save the more performance gain? Do oyu have to redraw the texture planes and sides on every rotation?

  13. How do you scale it? Is it done similar to rotation then?

  14. How do you make sure you dont connect tje vertexes wrongly, causing weird planes and lines?

  15. What kind of coordinate is used so that its not too slow on 32 bit? Is floating point big enough?

  16. If you add another figure, how do you make sure its drawn in front if its in front?

  17. If its transparent, how would you do this? How do you combine the colors on antialiasing and transparent colors?

  18. How do you combine the lighting with the colors, resulting in darker or lighter color?

  19. How do you make sure nothing is drawn outside of the visible window, how do you make sure the planes and axis that are inside the window, but not visible, are not drawn?

Thanks for explanation, Im happy to explore.

PS: You are just downvoting this because:

  • you dont know the answers or

  • you know my goals and disagree with my philosophy

  • you hate me all

  • you dont want to answer to keep telling me that i know nothing.

You cant deny these questions are valid thats why you have to downvote.

0 Upvotes

19 comments sorted by

10

u/mohragk Feb 22 '24

Learnopengl.com

-9

u/CarrotCakeX-X Feb 22 '24

that does not explicit answer this

13

u/mohragk Feb 22 '24

Maybe put in a little effort in figuring out things yourself

-13

u/CarrotCakeX-X Feb 22 '24

Why dont you just tell me if you know the answer? I asked very specific questions. Why do you answer for other newbies but not me?

7

u/NukemN1ck Feb 22 '24 edited Feb 22 '24

Your questions can hardly be answered in a single Reddit comment, especially if you have 0 presumed knowledge of computer graphics or programming. At best you'll get a very limited understanding of how your question might be answered, but not on any specific implementation, and it won't actually be very helpful to you. It's like asking how to solve an integral in calculus without knowing any algebra.

The first step is learning to code and basic geometry, and then following a guide like learnopengl.com will teach you how to actually implement your questions like question 1. With the knowledge you gain from following the guide you'll be able to more easily understand your other questions, too, and maybe not even have those questions anymore!

You can't rush this type of learning.

Edit: Reading the wikipedia entry on the Graphics Pipeline will also be useful and shouldn't require much if any programming knowledge, but it might require some knowledge of linear algebra and matrices.

9

u/electromaaa Feb 22 '24

Each question or so you asked corresponds to a step in the graphics pipeline. You have pretty good questions, why not use that as a guide to learn ?

-2

u/CarrotCakeX-X Feb 22 '24

 You have pretty good questions, why not use that as a guide to learn ?

I do

11

u/waramped Feb 22 '24

Answering these questions is basically an entire college course in Computer Graphics.

Read that book that u/krydx mentioned. Also this may help:

https://www.scratchapixel.com/lessons/3d-basic-rendering/get-started/gentle-introduction-to-computer-graphics-programming.html

And once you're ready to know a bit more about how a GPU works, there's this:https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/

Are you still on your quest to eradicate software bloat?

0

u/CarrotCakeX-X Feb 22 '24

 eradicate software bloat

What? I was never talking about bloat

1

u/waramped Feb 22 '24

You were posting about how computers seem to be getting slower and less efficient and such. That's called "bloat".

-4

u/CarrotCakeX-X Feb 22 '24

No bloat is when useless features do that

1

u/waramped Feb 23 '24

To clarify, I wasn't being critical, I'm genuinely curious if that's what all this curiosity is about.

7

u/Economy_Bedroom3902 Feb 23 '24

The questions are valid, it's just annoying to have a post that asks 20 seperate questions.  No one else does that.

6

u/waramped Feb 23 '24

I'll give this a legitimate try at a high level, to give you things you can do more research on:

  1. How do you draw it? Do you send vertex in order to the gpu and tell it to draw?

Yes. You send the vertices and tell the GPU that they represent triangles. Every 3 vertices will be 1 triangle.

2. I dont know if recent gpus do support quad rendering but most do break down to triangles? How do you determine the break down?

You can tell the GPU that every 4 vertices represents a quad, but it will just be triangulated eventually because the hardware only deals in triangles. There are several algorithms to triangulated a polygon. I have no idea which one any given GPU would use.

3. The whole figure would be one color blob, so we need some basic "lighting"? Like adding a darker color to the sides and the front a more lighter color? There would be no 3d figure visible else.

Yes, that's correct. This is called "shading" and where the term "shader" comes from.

4. How do you draw the planes of the triangles? How do you know where to draw at all there?

The triangle vertices are projected to something called Clip Space, where they are "clipped" against the screen, and possibly new vertices are created for them. Then these triangles are transformed into screen space where a process called Rasterization happens.

5. You would try to connect the vertexes to the neightbor, so that you have lines, but there is no infinite resolution, how do you determine where to place the pixel? Do you "mix" the pixel with the background? Like antialiasing?

This is rasterization. Antialiasing is a separate thing to deal with the case of the mathematical line not falling cleanly on a pixel.

6. How do you do the perspective? the quads last two vertexes would be more next to each other and less far away?

This is part of the projection matrix. This is a branch of math called Linear Algebra.

7. If you decide to rotate it, how do you compute the positions of all vertexes?

You use a transformation matrix. More Linear Algebra.

8. If you have a windows where you can press down your mouse to rotate the figure, you wouldnt redone the vertex again and again? How do you store the matrix? On rotation, the side that was before on the back could now be the front, so lighter color? And all lines and perspectives have to be redone? The planes have to be redrawn? Sounds like a lot of work.

Yup. Everything is done from scratch every frame.

9. You could also add a texture, some texture parts could be reused on multiple sides, how do you determine what position and coords on the texture?

This is called UV mapping and is part of the data sent with the vertices. They are coordinates that tell the GPU which part of the texture maps to a vertex. This data is then interpolated during rasterization.

10. How do you store the texture?

It's easiest to just think of it as a grid of colors in memory but it's more complicated than that in reality due to how the various memory caches work.

11. Wouldnt the texture get stretched if the figure side is bigger than the texture?

Yes, if you ever play a game and the texture gets blurry when you are close up, that's what's happening.

12. What part do you save after rotation? The more you save the more performance gain? Do oyu have to redraw the texture planes and sides on every rotation?

You don't save anything. Everything is redone every frame.

13. How do you scale it? Is it done similar to rotation then?

Yup, more linear algebra.

14. How do you make sure you dont connect tje vertexes wrongly, causing weird planes and lines?

It's just how you order the data to send to the GPU.

15. What kind of coordinate is used so that its not too slow on 32 bit? Is floating point big enough?

32 bit is standard. 16bit used to be common too but is mostly unsupported now.

16. If you add another figure, how do you make sure its drawn in front if its in front?

This is called Z buffer or depth buffer. Basically there's a "texture" that stores the distance to each pixel. If the new thing is closer, it's used instead.

17. If its transparent, how would you do this? How do you combine the colors on antialiasing and transparent colors?

This is called "alpha blending". In physical terms it's Transmittance.

18. How do you combine the lighting with the colors, resulting in darker or lighter color?

This is called your "shading model" and it's a complicated topic. Look up Physically Based Rendering. In the old days it was simplified using Gourad or Phong shading.

19. How do you make sure nothing is drawn outside of the visible window, how do you make sure the planes and axis that are inside the window, but not visible, are not drawn? See #4.

5

u/Traveling-Techie Feb 22 '24

A majority of the things you list will be done by a graphics library. It will figure out final vertex positions and draw all the pixels.

The reason people don’t want to answer all your questions is that it would be a lot of work. It’s like going into a cooking sub and asking how you prepare everything on the menu at a gourmet restaurant. Thousands of words would be required to answer that.

If you want to learn how to think in 3D and structure 3D apps without programming (at least at the start) look into X3DOM.

https://doc.x3dom.org/tutorials/index.html

You’ll need to use an IndexedFacetSet to define 5 points and 5 faces.

2

u/[deleted] Feb 22 '24

I highly recommend this book: https://gabrielgambetta.com/computer-graphics-from-scratch/

Doesn't touch on the GPU side, but tells everything about mathematics and code involved in building everything from scratch (drawing individual pixels)

2

u/MagicWolfEye Feb 22 '24

Given that you say that you don't code, I don't know exactly what you actually want to learn.

Also, you might want to watch this
https://www.youtube.com/watch?v=bGe-d09Nc_M

2

u/stuaxo Feb 23 '24

OpenGL is not a bad place to start.

Find out how to draw a single triangle to the screen and go from there.