Advertisement

IT FINALLY WORKS!!!

Started by February 20, 2003 01:57 PM
8 comments, last by Marty666 22 years ago
The heightmap you''ve been helping me with finally works! The problem was very simple... the z value I read from the file was read as GLubyte... when I put it in the vertexarray with GL_INT''s I had to convert it to an integer... I used: (int)readbyte, c++ didn''t complain anymore, but it didn''t show anything When I put all the height values to 1 my heightmap appeared... YES! nice feeling if you''ve been fucking around for it for 3 days... Still one problem, though... how do I convert an unsigned char to an int in c++? LOL I''m totally new with c++ and delphi allways let me put byte values in integers...
_____ /____ /|| | || MtY | ||_____|/Marty
static_cast(value)
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
Advertisement
Still a problem, the heightmap shows now, but lights won''t work properly, i set position with w value 0 (diffuse light should be directional). Still the whole terrain is lit evenly, so i can only see the contours.
Should I use glNormal or something? With just one triangle (my last program) It worked just fine without normals...

Marty
_____ /____ /|| | || MtY | ||_____|/Marty
I don''t know anything about your program, but yeah, you need normals. Also, make sure you''re using diffuse or specular(anything not ambient) as your lighting.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
I knew that your problem was unsigned byte and int
For lighting, u need normals or u can tell OGL to generate them...
You can convert like this
i = (int) c;
PM Times change... Excuse my poor english!
I converted with (int) the firts time, but that didn't work. unless you tell me that with static_cast it's much slower i'll leave it to static_cast..

All works now, just a few minor bugs. there are lines from one side to the other of the terrain (i rendered lines) that shouldn't be there. My loop for setting the index arrays goes something like this:

NOTE:
* I use WIDTHmap for both x and y because it's a square map.
* iArray = array of indexes

for (x=0; x..// -1 because last row has no next row
..// and again -1 cause we start at 0
..// together : -2
{
..goingback = !goingback;
..if (goingback != true)
..{
....for (y=0; y....{
......iArray[2*(x*WIDTHmap+y)] = x*WIDTHmap+y;
........// this row (x) this column (y). *2 cause we do 2
........// vertexes at a time
......iArray[2*(x*WIDTHmap+y)+1] = (x+1)*WIDTHmap+y;
........// next row (x+1) this column (y). *2 again
....}
..}
..else // Do the same, but count back
..{
....for (y=WIDTHmap-1; y>=0; y--)
......// -1 cause we end at 0
....{
......iArray[2*(x*WIDTHmap+y)] = vArray[x*WIDTHmap+y];
......iArray[2*(x*WIDTHmap+y)+1] = vArray[(x+1)*WIDTHmap+y];
....}
..}
}

I used the stupid dots instead of spaces because this forum takes out spaces. The structure is more clear this way

Where is the bug? I tried these formula's in a little drawing, but they seem bo be correct. When i'm back home i'll post a screenshot

[edited by - Marty666 on February 21, 2003 5:23:22 AM]
_____ /____ /|| | || MtY | ||_____|/Marty
Advertisement
Seems you mixed "index" space and "vertex" space.

Each time you generate a new index, you must add it AT THE END of your index array.

something like :

unsigned int i = 0;

for (...) {
goinback = !goinback;

for(...) {
iArray[i++] = x*WIDTHmap+y;
iArray[i++] = (x+1)*WIDTHmap+y;

and so on.

Note that the important thing is the use of the "i" variable.

Hope it helps.
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Sorry, my mistake...
iArray is not an actual array, it''s declared as:
GLint iArray = new GLint[NumVertex]

I think I can write to any offset in the mem block this way.

The program works, it shows the landscape, but at the end of each row a strange line goes all the way through the landscape.

The last part of the landscape seems random but it''s only 4 of the 256 rows of veretxes, so it seems to be 2 different bugs.

The vertex array is set up properly for sure.

Marty
_____ /____ /|| | || MtY | ||_____|/Marty
I understood that iArray was a GLUint[], but I was talking about the way you fill it : when you're traversing a row backward, you're filling your index array backward as well, so this row will end up as a forward-traversed row as well.

BTW when writing "AT THE END" of the array, I was meaning filling the array in a sequential manner. I understand that this was far from clear ;*)

I'm pretty sure you have a long line drawn every other row.
Am I wrong ?

[edited by - rodzilla on February 21, 2003 7:02:25 AM]
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
I found this on http://www.slug-production.be.tf/

// Copied from NVidia web site
inline void FloatToInt(int *int_pointer, float f)
{
__asm fld f
__asm mov edx,int_pointer
__asm FRNDINT
__asm fistp dword ptr [edx];

}

Use:
float a = 565.8f;
int i;
FloatToInt(&i, a);

PM Times change... Excuse my poor english!

This topic is closed to new replies.

Advertisement