Skip to main content
gamedev.net
🔒 Locked

Problem with code/algorithm in OpenGL

Started by BytePtr Mar 11, 2009 at 4:12 AM 4 replies 1.1k views
Original Post
BytePtr
BytePtr
There is one game, i want to make map editor for it. Map itself is made from simple block shapes. Nothing more. Game map stores specific numbers. Each number says to game engine what shape each block is. If for example number is 0 then this is just simple fixed size cube. If it's 1 then it's a slope etc... till ~60 of them. Map can contain any number and any of these blocks as much it can hold. There is no block coordinates (like X,Y,Z) or vertex information stored in file. They are hard coded in game and original editor. It's simple: predefined size of blocks are stored in map as specific numbers. Like i said above. Map size 256x256x8. To get a different shapes from specific co-ordinates i coded simple console app in Delphi.
var cube:integer;       
   
    ....
By editing map and saving it. The app shows correctly the shape type (nr) and it's coordinates. So i don't have problems getting the correct shape. Main problem is with OpenGL, code and algorithm. I don't know exactly where is the problem. This is code which reads shape type from map file and returns it in global variable "which".
procedure ReadGmp;
begin
  repeat
 
  until ms.Position>=ms.Size;
end;
Then the DrawIt procedure comes into the action. It contains all glVertex3f and stuff.
procedure DrawIt;
begin
   
           end;
end;
The main drawing function get's the shape and also calls DrawIt procedure to draw the shape it got.
// The main drawing function.
procedure DrawGLScene;
begin

  SDL_GL_SwapBuffers;
end;
What i need is that every specific shape must have drawn at it's own co-ordinates, let's say one block is at X: 5, Y: 18, Z: 8, slope is at X:28 Y:125 Z:1. And then another simple block at X:31 Y:88 Z:1 So it must draw or render only those blocks at their X,Y,Z positions. But the problem is: the code doesn't care about this, it draws all blocks, even if at that X,Y,Z is no shapes defined. Look the screenshot: http://www.onlinedisk.ru/view/98090/buggg.JPG I don't understand where is the problem? Is it in code, algorithm or in both? Maybe the code is not organized well? Maybe the code that gets numbers should not be in drawing loop? Can somebody give some hints or anything that can help? Im willing to explain more about this, if somebody don't understand it. [Edited by - BytePtr on March 12, 2009 9:27:58 AM]
CableGuy
CableGuy
I have skimmed through your code and there is something that I don't understand. In DrawScene, you loop through the map using x,y,z but when you call DrawIt you don't pass it these parameters? so essentially you are just calling DrawIt 256*256*8 times without any change unless x y and z are globals.
BytePtr
BytePtr
Yep they are globals.

Maybe my algo is completely wrong?


It should be like this theoretically.


loop x from 0 to 255
loop y from 0 to 255
loop z from 0 t 7

get_block_at (x,y,z)
if block_exists_at_this x-y-z then
draw_this_block;

end


but program draws everything. i.e all blocks. even if in actual map there is no blocks at every x,y and z. Just at some specific X,Y,Z places.



Something is really wrong.
CableGuy
CableGuy
1. Why do you read the map every frame?
2. What is the purpose of which and blkat in ReadGmp?
3. I don't see any mention of x,y,z,map.city_scape in DrawIt(can you post the entire code)

Also in your test you did map.city_scape[x,y,z] and in ReadGmp you index the map with a reverse order (z,y,x).

I guess that this is not close to the actual code, so it might help if you post it.
BytePtr
BytePtr
It doesn't matter, if it's x,y,z or z,x,y. In both cases program returns correct
values, i.e slope types. Depends how 3D array is declared.
In this code its like: city_scape:array[0..7,0..255,0..255]

Sltype contains slope type, cube shape in other words.

"Which" is global variable. It is mainly for DrawIt procedure. So it gets correct
cube shape from ReadCmp at current X,Y,Z.


I loop through map because at every X,Y,Z there is cube shape stored. If any cubes at all. So if there is specific sltype stored, i want to draw it.

Yes there are no parameters for DrawIt. Shouldn't it draw the cubes correctly without the X,Y,Z if it's inside loop?
I think that is the place where bug lies.

I dunno, i can post code but whole code will take almost one page i guess.


[Edited by - BytePtr on March 11, 2009 5:33:16 PM]
BytePtr
BytePtr
Well, solved this problem.




There is alot to do but this a great inspiration and very good start to continue working on it.

I was thinking that i will drop this project, something held me back and now i am happy that i didn't.


When the editor will be finised one day, then the "credits" list in about box will be big.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.