Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Matrefeytontias

Pages: 1 ... 99 100 [101] 102 103 ... 133
1501
nSDL / Re: nSDL 1.0.2—A very fast & robust graphics library
« on: January 03, 2013, 04:24:14 am »
Bump,

I've several questions :

  • In my program, I'm loading a bitmap with SDL_LoadBMP(path), but it seems that relative path doesn't work. If I have image.bmp.tns in the same directory as my program, just typing SDL_LoadBMP("image.bmp.tns"); doesn't work. Is there a way to fix that ?

  • Second question, I have sprites that have transparent parts, but it seems that transparency isn't supported due to the NTI format and get replaced by white 0xffff. Is there a way to use transparent sprites or are they forbidden ?

    EDIT : in fact it's ok, I wrote several functions to resolve my problems :) including a masked form of SDL_BlitSurface, which I think I can post here :

    Code: [Select]
    void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
    {
        int bpp = surface->format->BytesPerPixel;

        Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

        switch(bpp) {
        case 1:
            *p = pixel;
            break;

        case 2:
            *(Uint16 *)p = pixel;
            break;

        case 3:
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                p[0] = (pixel >> 16) & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = pixel & 0xff;
            } else {
                p[0] = pixel & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = (pixel >> 16) & 0xff;
            }
            break;

        case 4:
            *(Uint32 *)p = pixel;
            break;
        }
    }

    Uint32 getPixel(SDL_Surface *surface, int x, int y)
    {
        int bpp = surface->format->BytesPerPixel;
    Uint32 value;
        Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

        switch(bpp) {
        case 1:
            value = *p;
            break;

        case 2:
            value = *(Uint16 *)p;
            break;

        case 3:
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                value = (p[0] & 0xff) | (p[1] << 8) | (p[2] << 16);
            } else {
                value = (p[2] & 0xff) | (p[1] << 8) | (p[0] << 16);
            }
            break;

        case 4:
            value = *(Uint32 *)p;
            break;
        }
    return value;
    }

    void nSDL_BlitSurfaceAlpha(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dst, SDL_Rect *dstRect, Uint16 alpha)
    {
    int x,y;
    Uint32 color;

    SDL_LockSurface(src);
    SDL_LockSurface(dst);

    for(y = 0 ; y < srcRect->h ; y++)
    {
    for(x = 0 ; x < srcRect->w ; x++)
    {
    if((Uint16)(color = getPixel(src, x + srcRect->x, y + srcRect->y)) != alpha)
    {
    setPixel(dst, x + dstRect->x, y + dstRect->y, color);
    }
    }
    }
    SDL_UnlockSurface(src);
    SDL_UnlockSurface(dst);
    }

    Also, to resolve my first problem I set the directory of the program as the current folder :
    Code: [Select]
    char curDir[256];

    strncpy(curDir, argv[0], strflc(argv[0], '/'));
    chdir(curDir);

    ...

    size_t strflc(const char *src, char character)
    {
    size_t offset = strlen(src) - 1;

    while(offset > 0)
    {
    if(src[offset] == character) break;
    offset--;
    }
    return offset;
    }

1502
TI-Nspire / Re: Mode 7 with Ndless !
« on: January 02, 2013, 01:32:00 pm »
Thanks :)

I'll surely do an F-Zero game, I don't want to make something more difficult than that ;D

EDIT : ninja'd :ninja:

@ldebroux yeah I know, but I got problems with scaling (b/c the texture is too large), I didn't find any better way than growing the camera (I'll fix that later).

Someone has a solution for the file loading thing ?

1503
TI-Nspire / Re: Mode 7 with Ndless !
« on: January 02, 2013, 01:23:25 pm »
Heavy bump,

I'm back with Mode 7, and I planned to make a game using it :)

But for now, here's a screenie of an infinite textured and mode7'd ground, with full moves and rotations :



The quality here is because of the gif, it's far better on-calc :P

Also, I have a question : in order to avoid converting the texture in 242 lines of data, I access texture.bmp.tns using the absolute path (SDL_LoadBMP("/documents/Examples/texture.bmp.tns");). Is there a way to load the file texture.bmp.tns which is in the same directory as the executable ? I tried SDL_LoadBMP("texture.bmp.tns"); it just doesn't work.

Spoiler For Source code:
Code: [Select]
#include <os.h>
#include <SDL/SDL.h>
#include <fdlibm.h>

#define SCREEN_W 320
#define SCREEN_H 240
#define IMG_W 256
#define IMG_H 256

#define fsin(x) sin(x * M_PI / 128)
#define fcos(x) cos(x * M_PI / 128)

void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
Uint32 getPixel(SDL_Surface *surface, int x, int y);

int main(void)
{
SDL_Surface *screen, *bitmap, *sky;
SDL_Event event;
SDL_Rect skyRect;
skyRect.x = (skyRect.y = 0);
skyRect.w = SCREEN_W;
skyRect.h = SCREEN_H >> 2;
Uint32 color = 0;

float sinLUT[256];
float cosLUT[256];

float distance, hScale, line_dx, line_dy, space_x, space_y, scaleX = 200.0, scaleY = 200.0, space_z = 96.0,
offsetX = 870, offsetY = 1515;
int screen_x, screen_y, horizon = 0, x;

unsigned char angle = 0, speedX = 4, speedY = 4, speedAngle = 4;

SDL_Init(SDL_INIT_VIDEO);

screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, is_cx?16:8, SDL_SWSURFACE);

bitmap = SDL_LoadBMP("/documents/Examples/texture.bmp.tns"); // TODO : make the load relative

for(x = 0; x < 256; x++)
{
sinLUT[x] = fsin(x);
cosLUT[x] = fcos(x);
}

if(!bitmap)
{
SDL_Quit();
exit(1);
}

while(1)
{
SDL_PollEvent(&event);

if(isKeyPressed(KEY_NSPIRE_ESC))
{
break;
}
if(isKeyPressed(KEY_NSPIRE_DOWN))
{
offsetX -= cosLUT[angle] * speedX;
offsetY -= sinLUT[angle] * speedY;
}
if(isKeyPressed(KEY_NSPIRE_LEFT))
{
angle = (angle - speedAngle) & 0xff;
}
if(isKeyPressed(KEY_NSPIRE_RIGHT))
{
angle = (angle + speedAngle) & 0xff;
}
if(isKeyPressed(KEY_NSPIRE_UP))
{
offsetX += cosLUT[angle] * speedX;
offsetY += sinLUT[angle] * speedY;
}

for(screen_y = SCREEN_H/4; screen_y < SCREEN_H; screen_y += 2)
{
distance = space_z * scaleY / (screen_y + horizon);
hScale = distance / scaleX;

line_dx = -sinLUT[angle] * hScale;
line_dy = cosLUT[angle] * hScale;

space_x = offsetX + distance * cosLUT[angle] - SCREEN_W/4 * line_dx;
space_y = offsetY + distance * sinLUT[angle] - SCREEN_W/4 * line_dy;

for(screen_x = 0; screen_x < SCREEN_W; screen_x += 2)
{
if(SDL_LockSurface(bitmap) != 0)
{
printf("Can't access bitmap");
exit(2);
}
if(SDL_LockSurface(screen) != 0)
{
printf("Can't access screen");
exit(2);
}
color = getPixel(bitmap, (unsigned int)space_x % IMG_W, (unsigned int)space_y % IMG_H);

setPixel(screen, screen_x, screen_y, color);
setPixel(screen, screen_x + 1, screen_y, color);
setPixel(screen, screen_x, screen_y + 1, color);
setPixel(screen, screen_x + 1, screen_y + 1, color);

SDL_UnlockSurface(screen);
SDL_UnlockSurface(bitmap);

space_x += line_dx;
space_y += line_dy;
}
}

SDL_FillRect(screen, &skyRect, SDL_MapRGB(screen->format, 255, 255, 255));
SDL_Flip(screen);
}

SDL_FreeSurface(bitmap);
SDL_Quit();

return 0;
}

void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
    int bpp = surface->format->BytesPerPixel;

    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

    switch(bpp) {
    case 1:
        *p = pixel;
        break;

    case 2:
        *(Uint16 *)p = pixel;
        break;

    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
            p[0] = (pixel >> 16) & 0xff;
            p[1] = (pixel >> 8) & 0xff;
            p[2] = pixel & 0xff;
        } else {
            p[0] = pixel & 0xff;
            p[1] = (pixel >> 8) & 0xff;
            p[2] = (pixel >> 16) & 0xff;
        }
        break;

    case 4:
        *(Uint32 *)p = pixel;
        break;
    }
}

Uint32 getPixel(SDL_Surface *surface, int x, int y)
{
    int bpp = surface->format->BytesPerPixel;
Uint32 value;
    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

    switch(bpp) {
    case 1:
        value = *p;
        break;

    case 2:
        value = *(Uint16 *)p;
        break;

    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
            value = (p[0] & 0xff) | (p[1] << 8) | (p[2] << 16);
        } else {
            value = (p[2] & 0xff) | (p[1] << 8) | (p[0] << 16);
        }
        break;

    case 4:
        value = *(Uint32 *)p;
        break;
    }
return value;
}

1504
As soon as something has to be done with Qt, I'll help :)

1505
Humour and Jokes / Re: If there was tech support in botswana...
« on: January 01, 2013, 05:16:49 pm »
Maybe it's not that bad.

Gherkin is a strange word.

1506
Humour and Jokes / Re: If there was tech support in botswana...
« on: December 31, 2012, 01:55:29 pm »
Destroy your door.

Apocalypse didn't happen (what a problem)

1507
Humour and Jokes / Re: If there was tech support in botswana...
« on: December 31, 2012, 01:05:12 pm »
Don't stress, we never gonna give you up.

My dad is bothering me.

1508
ASM / Re: [z80 ASM] How do 8.8 maths work ?
« on: December 30, 2012, 07:21:20 pm »
It works, thanks :) (I think I could correct myself but it's 1 am :P )

1509
ASM / Re: [z80 ASM] How do 8.8 maths work ?
« on: December 30, 2012, 06:09:26 pm »
It seems that your multiply routine doesn't work... I tried :

ld hl,$0180
 ld de,$0200
 call HLtimesDE88
 bcall DispHL


It displayed 2 instead of 3.

1510
Axe / Re: [Axe] Mode 7 test
« on: December 30, 2012, 05:11:26 pm »
Yeah, of course I didn't think of getting directly into Mode 7 :P

1511
Axe / Re: [Axe] Mode 7 test
« on: December 30, 2012, 04:52:31 pm »
Yeah, but considering how low are my skills, I don't even know if I'll finish it someday :P

But I'll try anyway.

1512
ASM / Re: [z80 ASM] How do 8.8 maths work ?
« on: December 30, 2012, 04:03:42 pm »
Oh okay, it's in fact a multiplication/division involving a 24-bits number which is either for the multiplication the result or for the division the first operand. That's it ?

1513
ASM / [z80 ASM] How do 8.8 maths work ?
« on: December 30, 2012, 02:11:28 pm »
Hi guys,

I already know how to do 16-bits multiplication and division in z80 ASM, but how to extend them to 8.8 fixed point ?

In fact there are two questions in one : how do 8.8 work (guess the title) and how do I implement them ?

Thanks by advance :)

1514
Axe / Re: [Axe] Mode 7 test
« on: December 30, 2012, 01:58:26 pm »
Welcome in the world of ASM.

I think I'll try to make something similar, but seeing my ASM skills, I'm afraid that I won't get anything until a year or two D:

1515
F-Zero 83+ / Re: F-Zero Progress Thread
« on: December 30, 2012, 01:54:08 pm »
Bump,

do you still plan something for that, or is it totally dead ?

Pages: 1 ... 99 100 [101] 102 103 ... 133