PDA

View Full Version : trying to make a rpg engine..need help.



method5
03-24-2002, 08:34 AM
thanks everyone. it works.

[This message has been edited by method5 (edited 03-24-2002).]

method5
03-24-2002, 08:36 AM
please note: the first few structures are for the collision detection which i have not converted yet.. and if you want more info on the hosting.. goto method5.com and check plan2..

method5
03-24-2002, 08:37 AM
and if you want the .cpp file contact me on icq @ 21159213, aim contact: kdghsu or email jason@method5.com

copy of the test map file it loads:

20,20
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

[This message has been edited by method5 (edited 03-24-2002).]

harsman
03-24-2002, 10:45 AM
And exactly what error do you get when you run it? I'm guessing that information would be more valuable than your code.

method5
03-24-2002, 11:51 AM
Please see http://www.method5.com/opengl/screenshot.gif for a screenshot..

and I found out it has to do with the actual drawing of the map... cause when i comment that part out it runs without errors.

Jambolo
03-24-2002, 12:00 PM
Try compiling and running the program in debug mode. You will get more information about the error.

method5
03-24-2002, 12:21 PM
okay thanks guys.. I figured out what was causing the error.. it was calling the draw routine before i set up my camera..


but now.. it runs.. but doesnt display the map.. only a white box in the corner.. ?

you can try it if you wish.. ive updated the above code..

zeckensack
03-24-2002, 12:47 PM
In load_gl_textures(), replace glGenTextures(251, &tiles[251]); with glGenTextures(251,tiles);.

method5
03-24-2002, 01:00 PM
still nothing..

zeckensack
03-24-2002, 01:37 PM
From your drawing function:

for(i = 0; i<numberofobjects; i++) {
if (objects[i].objecttype == 1) {
...
}
}

You only initialize objecttype for object[0]. All other objects won't make the if statement so they won't draw. You also use the .x and .y members, which are again not initialized for anything besides object[0]. That explains why you only get a single box drawn.

zeckensack
03-24-2002, 01:40 PM
Oops! Disregard my last post http://www.opengl.org/discussion_boards/ubb/smile.gif

You need to add glEnable(GL_TEXTURE_2D); to your init code for your textures to show.

method5
03-24-2002, 01:41 PM
Originally posted by zeckensack:
From your drawing function:

for(i = 0; i<numberofobjects; i++) {
if (objects[i].objecttype == 1) {
...
}
}

You only initialize objecttype for object[0]. All other objects won't make the if statement so they won't draw. You also use the .x and .y members, which are again not initialized for anything besides object[0]. That explains why you only get a single box drawn.

Nope... cause object 0 is the character.. and the rest are not needed right now since i havent converted the npc coding... it has nothing to do with the map/camera anyway,,

zeckensack
03-24-2002, 01:45 PM
....
glutDisplayFunc(drawscreen);
glutKeyboardFunc(inputevent);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutMainLoop();
load_gl_textures();

do {
FocusCamera(0); // MAIN LOOP
} while (1 != 0);
return 0;

This is very very wrong. By calling glutMainLoop(), you're giving control to glut, everything after that call won't get executed.

Change it to this:

....
glutDisplayFunc(drawscreen);
glutKeyboardFunc(inputevent);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
load_gl_textures();
FocusCamera(0);
glutMainLoop();
return 0;

method5
03-24-2002, 01:45 PM
Originally posted by zeckensack:
Oops! Disregard my last post http://www.opengl.org/discussion_boards/ubb/smile.gif

You need to add glEnable(GL_TEXTURE_2D); to your init code for your textures to show.

Where exactually should I put it.. tried it in a few spots and none of them worked..

zeckensack
03-24-2002, 01:48 PM
Originally posted by method5:
Where exactually should I put it.. tried it in a few spots and none of them worked..

Into your main function, but put it before glutMainLoop();. Just like I said in my last post http://www.opengl.org/discussion_boards/ubb/wink.gif.

method5
03-24-2002, 01:49 PM
ok now I get an error.. it has to do with the load_gl_textures(); cause if i comment out it works. (well loads with no windows error box)

i think it has to do with my poorly coded thing to get filename..

itoa(t,tem,10);
temp = strcat(strcat("tile", tem), ".bmp");
tilesimage[t] = loadbmp(temp);

heh.. please help. im trying to get it like
tile#.bmp but not good with strings

DFrey
03-24-2002, 01:56 PM
You are improperly using strcat. Read about it.

zeckensack
03-24-2002, 02:01 PM
Originally posted by method5:
itoa(t,tem,10);
temp = strcat(strcat("tile", tem), ".bmp");
tilesimage[t] = loadbmp(temp);

heh.. please help. im trying to get it like
tile#.bmp but not good with strings

Yeah, this shouldn't even compile I think.

First of all, don't declare temp as a plain char*, this won't reserve any memory for the string, instead do this:
char temp[64];

Then try this:

sprintf(temp,"tile%u.bmp",t);
tilesimage[t] = loadbmp(temp);
This will get you tile0.bmp , tile1.bmp ,tile 20.bmp ...
If you want names like tile00.bmp, use "tile%02u.bmp" in sprintf
If you want names like tile000.bmp, use "tile%03u.bmp"

Oh, and you can scrap the 'tem' variable altogether.

method5
03-24-2002, 02:08 PM
ok thank you.. it kinda shows a map now...

but the tiles it shows.... are not correct... like it is only showing them in one color...

method5
03-24-2002, 02:13 PM
any idea why it would do this?? just show them in one solid color..

zeckensack
03-24-2002, 02:19 PM
Originally posted by method5:
any idea why it would do this?? just show them in one solid color..


for(i = 0; i<MaxY-1; i++) {
for(int j = 0; j<MaxX-1; j++) {
tile = map[dCameraX + j][dCameraY + i];

glBindTexture(GL_TEXTURE_2D, tiles[tile]);
glBegin(GL_QUADS);
glVertex2f(drawingx, drawingy);
glVertex2f(drawingx + 32, drawingy);
glVertex2f(drawingx + 32, drawingy + 32);
glVertex2f(drawingx,drawingy + 32);
glEnd();

drawingx = drawingx + 32;
}
drawingy = drawingy + 32;
drawingx = doffsetX;
}
Notice something? Yep ...
You need texture coordinates here!


glBindTexture(GL_TEXTURE_2D, tiles[tile]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex2f(drawingx, drawingy);
glTexCoord2f(1.0f,0.0f);
glVertex2f(drawingx + 32, drawingy);
glTexCoord2f(1.0f,1.0f);
glVertex2f(drawingx + 32, drawingy + 32);
glTexCoord2f(0.0f,1.0f);
glVertex2f(drawingx,drawingy + 32);
glEnd();

method5
03-24-2002, 02:23 PM
THANK YOU GUYS SOOO MUCH! IT WORKS!!

zeckensack
03-24-2002, 02:25 PM
I sure feel like a genius sometimes ... http://www.opengl.org/discussion_boards/ubb/biggrin.gif

method5
03-24-2002, 02:29 PM
considering i didnt know a thing about c++ or opengl on friday.. i feel like one too :-)