PDA

View Full Version : OpenGL Newbie Needs Help



Krak
04-28-2003, 04:26 PM
1.) Why is it that when you supply a file path\name, you hafta convert the "\"s into "/"s? Does it have something to do w/ some of the special commands you can use with \? i.e: "\n"

2.) My program doesn't work outside of my computer because it can't find the .bmp file.(And yes, I did supply the full path to the file) It's a simple program where I use a .bmp file to texture a cube. Would I hafta .zip up the game, and include the .bmp files I'm going to use for it to work outside of my computer?

3.) What's DWORD alignment?

4.)Using the same method you use to use bitmap textures, would I be able to make an animated GIF texture?

5.) What's HWND stand for?

6.)What's a window handle?

Watcher
04-28-2003, 04:50 PM
1) \ is the escape character. In order to actually use a \ in a string, you have to escape the escape character, ie \\. For example:

"C:\\Program Files\\OpenGL Stuff"

2) I think if you specify the directory with backslashes as above it will fix this issue.

3) A DWORD is a 32-bit number (WORDs are 16 bit, BYTEs are 8 bit, NIBBLEs are 4 bit). The way modern PC RAM is designed, it is much more efficient to align your variables on every 32 bits in RAM rather than at some other arbitrary point (accessing an unaligned DWORD will double the time it takes to read the variable from RAM). Unless you're coding in assembly, however, the compiler usually handles this for you if its any good.

4) Potentially, you could make an animated GIF texture. However, the algorithm for this would be fairly compilcated -- you can't just bind the texture and expect it to animate itself. You would have to manually switch textures from one frame of the GIF to the next. You could do the same thing with loading 4 different bitmap textures, and then swapping them out with each other based on a timer.

5) HWND is a handle to a window. In WIN32 programming, every window has a handle, which is basically the ID number of the window. In order to access any information about the window, ie, obtain a device context for OpenGL to use, you must have its HWND window handle.

6) See above.

Hope this helps you out.

Krak
04-28-2003, 05:13 PM
3) A DWORD is a 32-bit number (WORDs are 16 bit, BYTEs are 8 bit, NIBBLEs are 4 bit). The way modern PC RAM is designed, it is much more efficient to align your variables on every 32 bits in RAM rather than at some other arbitrary point (accessing an unaligned DWORD will double the time it takes to read the variable from RAM). Unless you're coding in assembly, however, the compiler usually handles this for you if its any good.

I think I lost you on that. Could you give me a complete retard's guide to how this works, and why bitmap dimensions have to be powers of 2?

Watcher
04-28-2003, 07:15 PM
A typical memory layout is something like this:




-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
BUS-> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|


Each block in the memory is a byte. The 80586 (Pentium) and higher processors have a 32-bit data bus, which means that they can transfer 32-bits of information from RAM at a time. The way it does this is to read a 'row' of memory, supposing your DWORD is correctly aligned.




-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----| <-- read this
-----> |----| |----| |----| |----|
BUS-> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|


However, suppose you have a non-aligned DWORD:




-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----| <--- read this
-----> |----| |----| |----| |----| <-- and this
-BUS-> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|
-----> |----| |----| |----| |----|


The processor now must read 32-bits from the first row, and then 32-bits from the second row -- it just discards the extra data. Effectively, this doubles the amount of time used to access RAM.

As for the texture sizes being a power of two, I'm not really sure. The only thing I can see significant about it is that a (power of two) by (power of two) sized image will always be an even amount of kilobytes (ie, 4K, 192K, not 4.3K or 192.1K) in memory size. OpenGL probably can deal much more efficiently with texture images that are even in size like this, but I'm not sure of the specifics. I'd be interested to know if anyone else knows why.

[This message has been edited by Watcher (edited 04-28-2003).]

Deiussum
04-29-2003, 04:20 AM
Originally posted by Krak:


2.) My program doesn't work outside of my computer because it can't find the .bmp file.(And yes, I did supply the full path to the file) It's a simple program where I use a .bmp file to texture a cube. Would I hafta .zip up the game, and include the .bmp files I'm going to use for it to work outside of my computer?



If I understand you right, the BMP shows on your computer, but not when you give someone else the .exe? If so, yes, you DO have to supply the BMP file with the exe. And if you are hard coding the full path, yet want to distribute this to somone, you probably should not hardcode the path, but load it out of the same directory that the .exe resides. That way, if you give it to someone you don't have to tell someone, "Put the BMP file in C:\Program files\My app\Images\Etc\."