### GameDev General

Pages: 12345... 7
What are sin and cos?

 What are sin and cos?

Opposite over Hypotenuse and Adjacent over Hypotenuse.
Thanks I guess.

How can I calculate where parts of a GUI go?
closed account (3qX21hU5)
The same way you calculate where everything else goes? Use the coordinate system...
Coordinate system? Those are world coordinates.

I want to place it on specified pixels, similar to SFML.
If you're using OpenGL you should just be able to draw Quads (IIRC).
I am drawing quads. I can't figure out how to make it pixel-perfect, it's always too big.
OpenGL expects the coords you give it to be in clip space. This means that (after perspective divide):

X= -1 is the left edge of the screen
X= +1 is the right edge of the screen
Y= -1 is the bottom of the screen
Y= +1 is the top of the screen

If you want to plot something in "pixels" you will need to scale your positions to that boundary. This could be done like so:

 ``12`` ``````out.x = in.x / (screensize.x / 2); out.y = in.y / (screensize.y / 2);``````

Or you could set up a matrix to do the same thing.

Of course... if you read the arcsynthesis tutorial... all of this should become apparent. ;P Seriously... read that thing. I know it's big... but if you're serious about learning OpenGL, it's amazing.
It starts with Shader 3.0 though. My computer can run it, but I'd like 2.0 shader tutorials.

(Which are surprisingly scarce. All I find is fixed-function pipeline and 3.0+)
Last edited on
Are you making games for current and future computers, or are you making games for old relics? ;P

OpenGL 2.x and OpenGL 3.x are completely different beasts. So it makes sense that if he's explaining 3.x he's not going to talk about 2.x. It's like talking about Win95 in a WinXP tutorial.
Last edited on
Both I guess. Lol.

But are there any tutorials on it? I found one but I lost it in a power outage.

Speaking of old machines I actually have a vintage machine in my room. I use it as a media server. I back up my work on there.

I think it's a Dell Optiplex gx110. (Something like that).
Last edited on
You may as well forget about supporting both OpenGL 2.x and 3.x; like Disch said, they're completely different and to try to support both would make your code needlessly complex.

I don't know how much it differs from 3.x, but I even found a book about 4.x a while back: https://openglbook.com/the-book/ (seems like the server is down though)
I want to use 2.0 shaders.

I have a minimum spec base machine I'd like to support. Wouldn't older shaders work on new hardware? How does minecraft do it?
Last edited on
I don't know much about OpenGL tbh.

On a different note;
How do other people calculate framerates? Here is the code I'm using:
 ``1234567891011121314151617181920212223242526272829`` ``````class framerate_calculator { public: framerate_calculator() : current_sample(0), nb_samples(0), samples_total(0.f) { samples.fill(0.f); } void sample(float value) { samples_total -= samples[current_sample]; samples[current_sample] = value; samples_total += samples[current_sample]; if (++current_sample >= max_samples) current_sample = 0; if (nb_samples < max_samples) ++nb_samples; } unsigned value() const { return unsigned(1.f / (samples_total / float(nb_samples))); } private: static constexpr std::size_t max_samples = 100uL; std::array samples; std::size_t current_sample; std::size_t nb_samples; float samples_total; };``````

It works well if I set the framerate limit to 60, but if I increase it to 100 or remove it altogether, then I get an error that seems to scale (perhaps exponentially) with the framerate, e.g. for a limit of 100 fps the error is only ~2 fps (so it will display 98-100), but if I set the limit to 300 then the displayed framerate is between 190 and 250 fps, although the error probably doesn't account for all of that, but since the main loop currently does nothing other than process events, it should easily be able to maintain 300 fps (and indeed if I remove the limit altogether I get a reading of 350-380 fps, though part of the difference is likely to be down to the overhead of sf::Window::setFramerateLimit). I thought maybe the error was due to epsilon values in floating point calculation. Is there some way I can account for it?

Also, how can I make the change in the framerate smoother? I thought of using weight values but I couldn't see where to actually apply them to the values -- applying weights of 0.1 and 0.9 to the subtraction and addition respectively (and then in reverse) just makes the value either decrease (and then overflow) or increase. Manipulating the frequency of samples (currently every frame) or how often the mean is calculated (currently every 100th frame) makes it more stable, but isn't a real solution. I want something that turns it into a curve--perhaps a sigmoid function (edit: tried the sigmoid and arc tangent functions; they didn't really work)?
Last edited on
closed account (3qX21hU5)
 On a different note; How do other people calculate framerates? Here is the code I'm using:

For frame rates I use something similar to what Laurent did here https://github.com/LaurentGomila/SFML/wiki/Source%3A-FrameClock .
Last edited on
Thanks for the link, I'll check it out.
Last edited on
How many triangles should each "chunk" of my map take. I started off with 2048, however that just looks pointy.
The big trick to making polygons look smooth is not as much about "more polygons" as you might think. It is more about lighting and proper usage of normals and normal maps.

Again the arcsynthesis tutorial goes over all of that.
@Disch
Thanks for that link, I bookmarked it for when and if I get into 3D game programming.
Is assembler ever used nowadays in Game Programming?
Pages: 12345... 7