Archived

This topic is now archived and is closed to further replies.

fors

Need help porting DirectX code to OGL

Recommended Posts

fors    122
Hi, I am learning game programming from a book that uses DirectX to code everything, and since I have no knowledge (and shallow knowledge in OGL I might add) in DirectX could I get some help me with it? Someone might say get an OGL game programming book, but since I am using OGL for a 2D isometric game, it''s hard to find a book like that. If anyone knows such book, please let me know. Anyway, here are my questions. 1. The book uses LPDIRECTDRAWSURFACE7 as a surface to represent a tileset. What would be the perfect counterpart in OGL? 2. In OpenGL, how do I read in a bitmap image and read a pixel at (X, Y) and do certian actions based on the color? The Red OpenGL Guide said this is not supported in OpenGL (only supports framebuffer<->memory). 3. Should I consider alternative data structures etc. if the one used in DirectX is too DirectX dependant (like DDBLTFX)? Thanks for helping out a newbie.

Share this post


Link to post
Share on other sites
Null and Void    1088
1. You use a texture, obviously.
2. The Red Book did not say that. You can''t read the data from a texture that''s already in video memory, but you can do anything you want to the raw data of the image. Write your own bitmap loading function (it''s really easy) or find one online. If it is any good you should quickly see how to access the raw data of the image after loading it.
3. OpenGL doesn''t really use any structures, so the short answer is yes. If you''re wondering about how to replace color keying: use alpha testing (faster) or alpha blending (slower, but more potential features).

Share this post


Link to post
Share on other sites
zedzeek    529
>>2. In OpenGL, how do I read in a bitmap image and read a pixel at (X, Y) and do certian actions based on the color? The Red OpenGL Guide said this is not supported in OpenGL (only supports framebuffer<->memory).<<

what exactlly do u want to do?

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
a person    118
stick with directdraw for what you are doing. directdraw does not translate too well to opengl. when you start understanding what you are doing, then considering learning opengl and rewriting the engine to use textured quads and such. write now though you will be doing yourself are large disservice. if you really want to use opengl, go get a opengl book and learn how to code *3D* games.

2. reading opengl screen buffer is quite slow and useless for anything other then screen shots.

i will again stress, opengl is not the right tool for the job in this case. dont let your ms hate and opengl love blind you. learn directdraw with the book. or if you really want to learn two apis at once like an ignorent fool, get a dx8 book that does isometric games and translate that to opengl.

if you are not understanding the concepts the book is teaching you are not learing. if you at not learning then you cant hope to apply the knowledge to other apis. you shudl when you are done with the book understand enough about how isometrics games work and understand opengl (nehe.gamedev.net) you will not need the book to write you game (well you may need it for reference but not need to rip every line of code).

tip of the day: NEVER write a wrapper for an api you dont know especially if its to use another api you know very little about.

Share this post


Link to post
Share on other sites
invective    118
quote:

1. The book uses LPDIRECTDRAWSURFACE7 as a surface to represent a tileset. What would be the perfect counterpart in OGL?


There is no perfect counter part in OpenGL, because its a 3d API. You can use textures instead, but you need to be aware of the limitations on textures imposed by your graphics driver (size must be square power of two between 64-256 on older cards. new cards can do rectangles and much higher resolutions). Its not really a problem with tile based games as long as you design your tiles properly (you may want more than one tile to share a texture). For instance, make all tiles 32x32 and store 16 of them in a single 256x256 texture.

quote:

2. In OpenGL, how do I read in a bitmap image and read a pixel at (X, Y) and do certian actions based on the color? The Red OpenGL Guide said this is not supported in OpenGL (only supports framebuffer<->memory).


Unlike DirectX, OpenGL has no graphics files loaders. You can write your own loaders (24 bit raw, bmp, and tga are easiest because lack of compression), but i suggest you save yourself the trouble and use libpng (www.libpng.org). PNG has compression and alpha channels, so its usually a good format to work with. If you just want to check the pixel values of a particular pixel in a texture, i suggest you keep a copy of the texture in system RAM instead of trying to read from video memory (SLOW!!!). If you are just trying to do collision detection or soemthing, just stroe a mask with the relavant information -- you don''t need all 24 or 32 bits of color information.

quote:

3. Should I consider alternative data structures etc. if the one used in DirectX is too DirectX dependant (like DDBLTFX)?


Many of the directX structures are really for specific functions, in which case many of the fields will be useless to you. If you want to be able to switch back and forth between OpenGL and directx then you might want to use them, otherwise forget it.

Making a 2D game in openGL shouldn''t be too difficult once you get down the basics of setting up and ortho view, drawing quads, and using textures. You probably need to devote the most time to understanding textures.

Share this post


Link to post
Share on other sites