Worth going through the effort with Xcode 2.5?

Member
Posts: 351
Joined: 2002.04
Post: #16
I must be missing something here, if I #include "util.h" I get: "unknown symbol '_testFunc'" and a warning: "'testFunc' is used but never defined". But if I #include "util.c" it compiles and works fine. But shouldn't I be including the header file and not the C file? The code for those files are simply:

util.h
Code:
static void testFunc();

util.c
Code:
#include <stdio.h>            /* Header File For Standard Input / Output */
#include <stdarg.h>            /* Header File For Variable Argument Routines */
#include <string.h>            /* Header File For String Management */
#include <stdlib.h>
#include "misc.h"

static void testFunc()
{
    printf("Hello");
}

Is there an Xcode setting I need to change or something?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #17
You should not #include the .c file. Just add it to your project (and make sure it's ticked for your target, but that should be the default).
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #18
Yeah that's what I thought I did to begin with. I might just recreate the files from scratch and see how I go.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #19
oh oh wait.

"static" is *not* what you want. "extern" or nothing in the header, nothing in the .c file.
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #20
*Slaps forehead*

Of course! Told you I'd been away from C too long. Smile
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #21
Here's an odd one - with my menu screens now showing up I've found the texture coordinates inverted from my old code. Not a big problem - I can flip them easily but I'm still curious as to why this may be?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #22
Because you changed how they're loaded Rasp
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #23
So with one method of loading (either my old one or now with libpng) they are essentially upside-down in memory?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #24
That would be my guess. Particularly now you've confessed you are using different code Wink
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #25
Yep, I'm using your SimpleImage wrapper for libpng OneSadCookie. Wink So easy to use so big thanks!

I was using Quicktime to load the textures before.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #26
SimpleImage loads the image the normal way up for OpenGL (0,0 in lower left). The simplest way to use QuickTime would load upside down (0, 0 in upper left). If you want things back to upside down (no reason why you shouldn't), there's code in SimpleImage to set the row pointers going upward:

Code:
unsigned int row;
    for (row = 0; row < height; ++row)
    {
        PNG_rows[height - 1 - row] = PNG_image_buffer + (row * 4 * width);
    }

That can be changed to make 'em go downward:

Code:
unsigned int row;
    for (row = 0; row < height; ++row)
    {
        PNG_rows[row] = PNG_image_buffer + (row * 4 * width);
    }
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #27
Cool, thanks for the tip.

That's actually a tough decision because I'd like to get into the headspace of thinking about 0, 0 being lower left since it is the mathematical/opengl way of doing things. But on the other hand I'm so used to thinking about 0, 0 being upper left since that is the screen standard that the other way with texture coords might confuse me.

Either way - thanks again, great to know I have options.
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #28
Okay, another problem.

My old 3D models are stored in the data fork of the model files. This is not the way I would do this nowadays starting from scratch but if I can still load those files with no problems I'd be happy to leave them as is.

I've brought my model loading code across and I don't get any errors but it seems the numbers I'm getting back in the data are a little crazy. For example, a GLuint to store the width of a texture is coming back as 1073741824 when it should be 128.

I was wondering if this could be a problem with big/little endianess?
Or if not, any clues?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #29
Looks like an endianness problem, though the numbers don't quite match up... 1073741824 is 0x40000000, while 128 is 0x00000080. In any case, you'll probably want to use something like this for binary file I/O:
Code:
#define swapInt32(int32) ((((int32) >> 24) & 0x000000FF) | \
                          (((int32) >> 8)  & 0x0000FF00) | \
                          (((int32) << 8)  & 0x00FF0000) | \
                          (((int32) << 24) & 0xFF000000))

#if defined(__BIG_ENDIAN__)

#define swapInt32Big(int32) (int32)
#define swapInt32Little(int32) swapInt32(int32)

#elif defined(__LITTLE_ENDIAN__)

#define swapInt32Big(int32) swapInt32(int32)
#define swapInt32Little(int32) (int32)

#endif

You'll just need to use swapInt32Big on each integer as you read it in.
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #30
Thanks ThemsAllTook, I think the 1073741824 actually should be 64 now if that makes more sense. I did a quick swap on a different integer earlier and it gave me a much more appropriate number so I think that is the problem.

I haven't had a chance yet to implement the swapping for the loading code, will the code you provided work for shorts and longs? Some other code I had researched was using different functions for the different types.

Thanks for the help.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Worth the trouble? NelsonMandella 7 3,950 Feb 7, 2010 05:48 PM
Last Post: cmiller