Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lazy Foo

Member Since 07 Sep 2004
Offline Last Active Today, 01:30 AM
*****

#4968854 Give me your source code

Posted by Lazy Foo on 12 August 2012 - 04:06 PM

Very rarely have I seen anyone really learn anything from just looking at other people's source code without some sort of explanation attached to the code. It doesn't do you much good to see what's there if you don't know why it's there.

You should probably look into some engine design books. I personally learned a lot from Game Physics Engine Development. It actually went into why did things the way it did, alternative ways to do things, and the cost/benefit of doing it different ways.


#4968661 Cross-platform Extensions (porting from Linux -> Windows)

Posted by Lazy Foo on 12 August 2012 - 03:46 AM

The error I was getting was a "Missing GL Version" error on glewInit().


Are you calling glewInit() after calling SDL_SetVideoMode()? There needs to be an active OpenGL context for GLEW to work.


#4968656 Question about Encapsulation (OOP)

Posted by Lazy Foo on 12 August 2012 - 03:25 AM

But what if the variable/field does not need and specific range/requirements, if this is the case should I just declare it as public?


It's still handy to be able narrow down where a variable is being accessed down to 6 lines of code from get/set methods. Often times when deubgging a realtime game I'll get weird values for an object variable. Since the only way to get to it is through the accessor method, I can very easily put one conditional breakpoint in the get function as opposed to having to find every occurrence of the variable being accessed and putting break points there.


#4968634 Question about Encapsulation (OOP)

Posted by Lazy Foo on 12 August 2012 - 01:32 AM

Because it allows you to control exactly how a variable is used.

I had a practical example of this when I developed my iPhone App. Back then the place I was working for wanted to support the iPhone 3GS/4, iPod Touch 3rd/4th gen, and iPad which were the most recent devices. They also wanted the iPad to support native resolution textures (overkill in my opinion, but they were signing my checks).

This means I had two sets of textures, low and high res for the 480x320, 960x640, and 1024x768 resolutions the devices used.

I had an OpenGL bitmap font rendering class that had a scale attribute that controls how much the font was stretched from the original. What I forgot to account for when coding everything (I pretty much coded the entire thing for 3rd gen iPod touch because that was our low end) is that the scale calculations would be slightly different for the retina and iPad displays.

So all I did was add a default scale attribute to my bitmap font class. Took me all of 5 minutes to code and test.

Had I just kept the variable public, I would have to ctrl replace my way through the code or do some grep voodoo.

As a general rule of programming you always want to keep your modular and loosely packed so you can easily adjust the pieces you want to without messing up the rest of the code. Encapsulating your variable with accessors and mutators allows you to very easily control and adjust how the variable/object is used.


#4968597 Cross-platform Extensions (porting from Linux -> Windows)

Posted by Lazy Foo on 11 August 2012 - 08:25 PM

My first solution was to use GLEW, but glewInit() failed in my native Linux build for whatever reason. I played around with it a while, but had no luck, so I decided to stick with what I have. The code is already far enough along that I shouldn't have to rewrite it. The new code works fine using glXGetProcAddress(), but for whatever reason, it's not linking wglGetProcAddress().

As for other libraries, I'm using SDL, SDL_image, SDL_net, and SDL_mixer.


SDL actually has the ability to get the address of and OpenGL function if you want to use that, but I would recommend getting glew working.

Although I would recommend getting glew working because it will be a huge pain to get all the OpenGL functionality for a modern OpenGL program. What exactly was the error glew was giving you?


#4968593 Cross-platform Extensions (porting from Linux -> Windows)

Posted by Lazy Foo on 11 August 2012 - 07:58 PM

Just use GLEW. You will get every function available on your system and it's easy to check your available functionality.

Compare your code to this (from my GLEW tutorial)
[source lang="cpp"] //Initialize GLEW GLenum glewError = glewInit(); if( glewError != GLEW_OK ) { printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) ); return false; } //Make sure OpenGL 2.1 is supported if( !GLEW_VERSION_2_1 ) { printf( "OpenGL 2.1 not supported!\n" ); return false; }[/source]

Not only that it gives you some shortcuts. FBOs didn't get promoted to core until after 2.1, but I was still able to treat them as core in an OpenGL 2.1 context thanks to the syntactic sugar glew provides.

Edit: Also are you using what additional libraries besides OpenGL are you using? I know certain libraries like SOIL require it to be in the linker before OpenGL32.


#4968565 Best way to follow up a tutorial?

Posted by Lazy Foo on 11 August 2012 - 05:48 PM

And What happends if I'm trying to follow up a very large tutorial?
Actually, the tutorial has 46 chapters, and each chapter has a lot of lines of code...
It's very difficult to me to make my own code without looking the sample.
I'm trying to learn DirectX 11 (Direct3d 11, etc).

I should initialize the window with Win32 API, and then the d3d. It's very delicate Posted Image
I need to copy all the code because I can't memorize all.

Should I hold all the functions, flags, etc?
How could I hold that information?


Josh Petrie, Lazy Foo
Thank you very much


Cut it up into testable pieces. Get one piece working, then get another piece working, then get another piece working, etc.

Also, people have different code and software architecture standards. The way I code my tutorials is probably different from the way you code you programs. One way that's always worked for me is porting a lesson's code to work with my personal framework.


#4968531 Best way to follow up a tutorial?

Posted by Lazy Foo on 11 August 2012 - 04:41 PM

Do something with it to test that you've actually learned from it.

If you're using a tutorial that comes with prebuilt sample code I recommend reengineering from the ground up to make sure you actually understand how it's put together.

I also recommend using it in an actual game project because thing is tutorials are actual often build for simplicity's sake and don't scale well when going from tutorial demos to actual large projects.


#4967755 A Problem in drawing 2D transparent shapes with ortho

Posted by Lazy Foo on 09 August 2012 - 06:34 AM

In that case you want to
1) Draw your 3D scene first with depth buffer enabled.
2) Clear/Disable the depth buffer and enable blending.
3) Draw the text over the 3D scene.
4) Swap buffers to update the screen.


#4947086 Open source code for a beginner

Posted by Lazy Foo on 07 June 2012 - 10:27 AM

I found this on LazyFoo's website. http://lazyfoo.net/g...locks/index.php and it's working code, but there are a lot of global variables, C style functions that should be part of a class object, and so forth. I'm not bashing his code, Ive written far worse myself.


Notice how I very specifically noted that that the source for the game is how not to to make game, in bold and capslock so you know I'm serious. :)

You want to know the best way to learn design? Stop going around to other people's projects hoping you'll find some magical piece of wisdom and go out and get your hands dirty.


#4914446 Can't get SDL_image to work

Posted by Lazy Foo on 19 February 2012 - 12:22 AM

I released an update to the website tonight regarding this actually.

When grabbing the library files, did you get the x86 or the x64 versions? When compiling, most compilers compile to 32bit. You should be using the x64 libraries only if you're compiling a 64bit binary, not if you're using a 64 operating system.


#4834089 Made an iPhone App, wrote an article about my experiences

Posted by Lazy Foo on 11 July 2011 - 07:59 PM

So I got offered to make an iOS game to promote a book for the tween crowd. It was a simple card game and I managed roll a prototype in a few afternoons. I was estimating the rest of the project would be done in a month.

6 months later the game was finally ready for the AppStore. I wrote an article about my experiences in having to self develop an App.


#3364085 SDL_Image... Entry point not found in SDL_Error

Posted by Lazy Foo on 23 November 2005 - 10:06 AM

Did you put the things in the linker in the right order?




PARTNERS