Jump to content
  • Advertisement
Sign in to follow this  
TDP owns

Can't convert bin. ascii to float

This topic is 4402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to create a OpenGL heightmap loader. Using: Code::Blocks 1.0 /GNU GCC I modified the OpenGL example that came with C::B. The heightmap itself is a 768x768 grayscale binary file. The problem is, that the converted float equals 0., it should more like 0.0 (0x0 on the heightmap). anyway heres my code: -------------------------------------------------------------------------- /************************** * Includes * **************************/ #include <windows.h> #include <gl/gl.h> #include <fstream> #include <string.h> using namespace std; /************************** * Function Declarations * **************************/ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC); void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC); void LoadFile(); float HM[767][767]; /************************** * WinMain ... -------------------------------------------------------------------------- void LoadFile() { char Buffer [589823]; int x; int y; float z; long k; char* t; char bfr [6]; //589824 bytes (0 - not counted) 768x768 ifstream File("hm.b",ios::in | ios::binary); File.read (Buffer, 589823); File.close(); for ( y = 0; y< 767; y++ ) { for (x = 0; x < 767;x++) { z = (float)Buffer[k]; HM [x] [y] = z; k++; } } gcvt (HM[767][767],6,bfr); t = (char*)bfr; MessageBox(NULL,t,"t",MB_OK); // is there any other way to check variable values? } -------------------------------------------------------------------------- wth am i doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
wha?
character array?
im converting the characters in the array one by one to floats,
then putting them in a 2d array.
or am i missing something?

if im doing anything stupid then plz tell me, because for me it looks fine and should work...

Share this post


Link to post
Share on other sites
Oh... sorry... I was a bit quick there and didn't see the indexing. Do you want to convert the ascii number to float? then this is what you want:

(float)(Buffer[k] - '0')

Share this post


Link to post
Share on other sites
Actually it doesn't work,
atleast i got some non-zero values to work with.
Im quite sure the problem lies in the converting,
so i've got some serious testing to do.

Anyway thanks for the help.

Edit:
LOL, never use a flat heightmap for testing...
The loader works fine, could be more accurate though.

Share this post


Link to post
Share on other sites
Initial value, zero i guess.
Im using the k as a offset for reading through the ascii string and
increasing it by one each x-loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!