Results 1 to 3 of 3

Thread: newbie q about GLfixed

  1. #1
    Junior Member
    Join Date
    Nov 2004
    Location
    Maryland
    Posts
    2

    newbie q about GLfixed

    Hello everyone,

    I am working on my first open gl es app and I have a question that may be something I have over looked.

    If I am using GLfixed and I want to have a float value like 1.0056 I am not able to do my normal shifts on it. Right now I am basically saying take the whole 1 and the dec 0056 and do the shifts to make them a fixed float. But, of couse the 0056 truncates down to 56 which totaly messes everything up. Is it possible to have decimal values that start with 0's?

    Of couse any help would be appreciated. If I come up with anything I'll also update this post.

    Thanks,

    Jeff

  2. #2
    Member
    Join Date
    Oct 2004
    Location
    Bangalore, India
    Posts
    44

    Re: newbie q about GLfixed

    You convert a float to fixed by multiplying by 65536.

    #define FLOATTOFIX(x) (x * (1<<16))

    or this may work as well
    #define FLOATTOFIX(x) (x * 65536)

    Convert a fixed back to float - divide by 65536

    #define FIXTOFLOAT(x) (x / (1 << 16))
    or
    #define FIXTOFLOAT(x) (x / 65536)

    You might want to look into fixed point maths. The following site is a good starting point http://gameprogrammer.com/4-fixed.html

  3. #3
    Junior Member
    Join Date
    Nov 2004
    Location
    Maryland
    Posts
    2

    Re: newbie q about GLfixed

    Thanks for the reply gautam. The thing I'm stuck on is that I'm working in BREW and we dont have floating point numbers so I cant say:


    FLOATTOFIX(0.002) (0.002 * (1<<16))

    because the 0.002 gets truncated down to 0 which wont work at all.

    The best I've managed to do was go from 0.0001 to 0.9999 and do that number as an int 0.0001 = 1 * 1<<16, and that works roughly but I still have bad truncation going on.

    UPDATE : I was going to post this reply and it sat in the background for like 3 hours but I finally figured out my problem. It wasn't a problem at all with my floats. It was a problem with my model loading. The first value of every matrix was ignoring if it was negative or not. Such an easy fix for such a stressfull night, but I guess thats how it goes.

    G-Night,

    Jeff

Similar Threads

  1. void glLineWidthx(GLfixed width) implementation on GLES
    By sukanya in forum OpenGL ES 1.X - fixed function hardware
    Replies: 0
    Last Post: 10-19-2010, 02:25 AM
  2. GLfixed data type
    By evening in forum OpenGL ES general technical discussions
    Replies: 9
    Last Post: 10-05-2004, 11:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •