Zanman777

Member

22

219 Neutral

• Rank
Member
1. Help on learning OpenGL! (Especially perspective projection)

I'm going slightly mad on this.   I've been trying to learn OpenGL. I've never learnt 3D programming / math (in a very solid way, anyway). I do know some basics about vectors, matrices, matrix multiplication, the identity matrix, how matrices store rotations, scaling and other transformations. I've read a couple hundred pages from 3D Math Primer for Graphics and Game Development, but that was at least a year ago. Furthermore, I guess there probably are some gaps in my 3D knowledge.   Lately, I tried to learn OpenGL through the Red Book. However, the book isn't very beginner-friendly. So after googling for a while I tried to learn from the arcsynthesis.com tutorials. I was doing very good until the perspective projection tutorial (http://www.arcsynthesis.org/gltut/Positioning/Tut04%20Perspective%20Projection.html). I don't get all that math on the "Camera perspective" section, tbh I think it's poorly explained (the rest of the tutorial is top-quality, though, gotta be fair).   From arcsynthesis I jumped to scratchapixel.com. The perspective projection matrix lesson (http://scratchapixel.com/lessons/3d-advanced-lessons/perspective-and-orthographic-projection-matrix/perspective-projection-matrix/) got me understanding things a bit better, but I'm starting to get really confused as scratchapixel.com and arcsynthesis.com seem to take slightly different approaches.   From what I understand, the homogeneous coordinates (as scratchapixel.com calls them) are acquired by dividing x,y and z by w. Those will then be the NDC (normalized device coordinates, as arcsynthesis calls them), right? Arcsynthesis seems to say that we "prepare" the perspective projection by setting the correct w coordinates for each vertex and letting the hardware do the rest:     However, the same Arcsynthesis states: ...then it proceeds to explain how to feed the clip space with already-processed vertex coordinates (in a way that gives the sense of perspective). I'm confused... Isn't that effect achieved by setting the correct w values for the perspective divide, which happens during the conversion from clip space to NDC???   Scratchapixel.com, on the other hand, defines the perspective divide as some sort of process of making w equal to z, so that dividing the coordinates by w will simultaneously make them homogeneous and fit into the z = 1 plane (which is considered the image plane in their example, or projection plane as arcsynthesis calls it).     So technically, the perspective projection occurs from the conversion from clip space into NDC, NOT before feeding the clip space coordinates (as arcsynthesis stated)! Am I right?   Things are starting to get really messy in my mind, and I'm wondering if I should just pick a textbook on this subject and learn it all the hard way. Subsequent concepts mentioned by scratchapixel.com like far view and near view are also unclear to me, though there are previous tutorials on scratchapixel.com that should enlighten me about those. The question is... should I keep on hopping from place to place to figure out stuff one thing at a time, or would I better grab a textbook? If so, which one?   Any help would be very appreciated. This is starting to harm my motivation to learn OpenGL. It really gives the sense of overwhelmingness (just made up a new word).

3. Fellow beginner game programmers

I'd enjoy programming with other people while we learn, and/or share ideas and thoughts. [snip]   Who's interested? You can add me on skype, my email is [deleted]   I've tried posting this in the classifieds but didn't get replies, so I'm trying here now, [snip]
4. Please tell me there's a way to set line width in SDL

My purpose was to draw buttons' borders. There is no way to specify the SDL_Rect border width, so I was trying the line approach. How can I draw a customisable button border, then?
5. Please tell me there's a way to set line width in SDL

I can't find a way to set a line width for the SDL_RenderDrawLine function, but I can't believe there's no way to set it. That's just... basic. Is there really no way to do so? Are the lines always 1 pixel wide, or what?   EDIT: Found an extension library (SDL_GFX) that provides that feature. It's wierd native SDL doesn't have that, though...

7. Quick question - problems declaring an SDL_Texture container

Oh, so with your code suggestion the SDL_Texture won't go out of scope? If so, it's piece of cake.   Yeah, it's working now, but getting rid of a member that only gets used on one member function would be a plus

9. Quick question - problems declaring an SDL_Texture container

Yes, SDL uses pointers to SDL_Textures. I tried to make a map of strings to SDL_Textures pointers instead. The problem is solved...temporarily. When a member function of that class tries to access/create/assign/whatever and so dereferences one of the pointers on the map, the problem pops up again - error: 'std::pair<_T1, _T2>::second' has incomplete type... So instead of getting an error on the map template instantiation, I get an error when using the map...
10. Quick question - problems declaring an SDL_Texture container

I want to define a class with a member map container that maps strings to SDL_Textures. The purpose is to hold loaded textures for reusage. class A { map<std::string, SDL_Texture> textures; }; When I try this, I get this error: error: 'std::pair<_T1, _T2>::second' has incomplete type How do I enforce the definition of SDL_Texture before the declaration of the textures map, to stop this error?
11. Can't pass string literal to constructor

I thought I had understood it. But now this site is confusing me... http://www.informit.com/articles/article.aspx?p=1852519 class C { int x=7; //class member initializer The way I understood it, this shouldn't be a class member initializer. It should be an assignment instead....     And how can these two be similar? That's exactly what I was trying in the first place!   class C { string s("abc"); C() : s("abc")
12. Can't pass string literal to constructor

OH, now I get it!! (And now I realize I was being very "duh"... But hey, I'm a newbie... Thanks for the patience)   So a class can take an assignment like this: class Foo { private: int bar = 0; }; But no initializations can happen outside the class initializer itself. Member initializations must happen in the class initialization too. Hence only this is valid: class Foo { public: Foo() : bar(0) {} private: int bar; } So... class Foo { private: int bar = 0; /* This ALWAYS works as an assignment operator, never as an initializer, even if no initializer is * provided for this member in the class initializer list / body. */ }; If I'm thinking wrong just tell me, please     So, what way would you use to turn around this? Personally I'd rather have an initializer together with the definition, so if I want to add new buttons later on, I don't have to add a definition in one place and an initializer in another. Would it be advisable to define & initialize the buttons in file scope instead (to be able to have them in one code line)? Just asking for a little tip from the pros here..     So there is a way to initialize on the member list with C++11? Or were you talking about the initialization list (with the ":", etc)? BTW I took the advice on avoiding using namespace std. Thanks for that one
13. Can't pass string literal to constructor

But if I do that, I need to have a bStart class (as far as I can tell, in your example Game's constructor is being delegated to a bStart's constructor)... Right? Or am I seeing it wrong?   Maybe it's obvious, but I'm a novice programmer, I'm really not understanding this... Thanks for the replies so far!
14. Can't pass string literal to constructor

Like that? Like what? Can you please elaborate? I didn't get what you mean...   I can initialize integers this way, but not strings (at least not using a string literal directly). By "this way" I mean: SomeDefinedClass Object(value1, value2, value3); Yes, I did #include <string> and using namespace std; on the header file
15. Can't pass string literal to constructor

Hello there.   I've been trying to make my very first game . Right now I'm at the menubuilding stage.   I'm trying to have a button class that can be initialized with its caption, X and Y relative coordinates, width and height. However, when I try to create an instance and initialize its caption, I get a compiler error: error: expected identifier before string constant Here's the code that matters (I'll point out with a comment the line where the error occurs).   GUI.h class Button { public: Button(string c, int pX, int pY, int w, int h) : caption(c), percX(pX), percY(pY), width(w), height(h) {} private: int width; int height; // The percentage of X and Y displacement relative to total screen width/height. // Counting from the left/up. int percX; int percY; string caption; }; game.h: class Game { public: // blablabla private: // more blablabla // GUI elements Button bSstart( "StartGame", 50, 20, 50, 5); // --> ERROR OCCURS HERE Button bOptions( "GameOptions", 50, 25, 50, 5); Button bHighScores( "HighScores", 50, 30, 50, 5); Button bAbout( "About", 50, 35, 50, 5); Button bExitAll( "ExitGame", 50, 40, 50, 5); I can't figure out what's wrong... I'm passing a string literal to initialize a string (the button's caption). Why would I need an identifier?