Fakemode instead of 16bpp?

Hello sdl,

Hello sdl,

tested under win2k, tnt2/m64/zx/pro, sdl-1.2.3
what is wrong with that code ? wrong shifting ?
please help, because i am getting out of my mind.

you need pic.bmp 800x600 :wink:

— main.cpp

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <SDL.h>
#include <math.h>

#include “Bitmap.h”
#include “BitmapMask.h”
#include “YTable.h”

long h1,h2,h3,h4;

unsigned long r,g,b;

unsigned long offset;

CBitmap *xtable;
CBitmap *rysunek;

CBitmapMask *vaddr01,*vaddr02,*vaddr03;

CYtable *ytable;

unsigned char temp_liner[800];
unsigned char temp_lineg[800];
unsigned char temp_lineb[800];

main (int argc, char **argv)
{
SDL_Surface *screen;

    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
            
            fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
            exit(2);
    }

    atexit(SDL_Quit);

    screen = SDL_SetVideoMode(800, 600, 16,
                    (SDL_FULLSCREEN|SDL_HWSURFACE));
    
    if ( screen == NULL ) {
            fprintf(stderr, "Couldn't set video mode %dx%d: %s\n",
                            800, 600, SDL_GetError());
            exit(3);
    }
    
    SDL_WM_SetCaption("Main", "main");

    /* Ignore app focus and mouse motion events */
    SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);

    //ytable = new CYtable(600,800);

    rysunek = new CBitmap(480000,"pic.bmp");
    
    vaddr01 = new CBitmapMask(480000);
    vaddr02 = new CBitmapMask(480000);
    vaddr03 = new CBitmapMask(480000);

    for (h1=0;h1<480000;h1++)
    {
            vaddr01->mBitmapMaskData[h1]=rysunek->mBitmapDataB[h1];
            vaddr02->mBitmapMaskData[h1]=rysunek->mBitmapDataG[h1];
            vaddr03->mBitmapMaskData[h1]=rysunek->mBitmapDataR[h1];
    }

    while ( SDL_PollEvent(NULL) == 0 ) {

            /* Lock the video surface */
            if ( SDL_LockSurface(screen) < 0 ) {
                    continue;
            }


            for (int h1=0;h1<480000;h1++)
            {

                    //r = (vaddr01->mBitmapMaskData[h1]&0xf80000)>>8;
                    //g = (vaddr02->mBitmapMaskData[h1]&0xfc00)>>5;
                    //b = (vaddr03->mBitmapMaskData[h1]&0xf8)>>3;

                    //((r>>3)<<11) +
                    //    ((g>>2)<<5 ) +
                    //  ((b>>3)    ); 

                    //              target_red = (source_color & 0xf80000) >> 8;
                    //        target_green = (source_color & 0xfc00) >> 5;
                    //        target_blue = (source_color & 0xf8) >> 3;

                    //      r = col >> 4;
                    //      g = b = col >> 3;
    
                    //      *(tmp++) = (word) ((r<<11) + (g<<5) + b);

                    //r = (((pixel&0xF800)>>11)<<3);                                        \
                    //g = (((pixel&0x07E0)>>5)<<2);                                         \
                    //b = ((pixel&0x001F)<<3);                                      \                       
                    
            RGB_FROM_RGB565(screen->pixels[h1]>>2,vaddr01->mBitmapMaskData[h1],
                                                                                      vaddr02->mBitmapMaskData[h1],
                                                                                      vaddr03->mBitmapMaskData[h1]);

                    //((long*)screen->pixels)[h1>>1] = RGB_FROM_RGB565(pixel, r, g, b)
                            //(((vaddr01->mBitmapMaskData[h1]&0xf800)>>11)<<3)|
                            //(((vaddr02->mBitmapMaskData[h1]&0x07e0)>>5)<<2)|
                            //(((vaddr03->mBitmapMaskData[h1]&0x001f)<<3));
                    
            }       
            /* Unlock and update the screen */
            SDL_UnlockSurface(screen);
            SDL_Flip(screen);
    }

    exit(0);
    return 0;

}

– Bitmap.cpp
// Bitmap.cpp: implementation of the CBitmap class.

#include “Bitmap.h”
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

CBitmap::CBitmap()
{

}

CBitmap::~CBitmap()
{
if (mBitmapDataR!=NULL) free(mBitmapDataR);
if (mBitmapDataG!=NULL) free(mBitmapDataG);
if (mBitmapDataB!=NULL) free(mBitmapDataB);
}

CBitmap::CBitmap(unsigned long size)
{
mBitmapDataR = (unsigned char*)malloc(size);
mBitmapDataG = (unsigned char*)malloc(size);
mBitmapDataB = (unsigned char*)malloc(size);
}

CBitmap::CBitmap(unsigned long size, char filename[])
{
unsigned char *mTemp;
FILE *bmp_file;

    unsigned long b1, b2;

    mTemp = (unsigned char *)malloc(54+(size*3));

    mBitmapDataR = (unsigned char*)malloc(size);
    mBitmapDataG = (unsigned char*)malloc(size);
    mBitmapDataB = (unsigned char*)malloc(size);

    if ((bmp_file=fopen(filename,"rb"))==NULL) MessageBox(0,"error","error",MB_OK);
    fread(mTemp,54+(size*3),1,bmp_file);
    fclose(bmp_file);

    for (b1=0, b2=0; b1<size; b1++, b2+=3)
    {
            mBitmapDataB[b1]=mTemp[51+(size*3)-b2];
            mBitmapDataG[b1]=mTemp[52+(size*3)-b2];
            mBitmapDataR[b1]=mTemp[53+(size*3)-b2];
    }

}

— Bitmap.h

// Bitmap.h: interface for the CBitmap class.

#if !defined(AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_)
#define AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CBitmap
{
public:

    unsigned char   *mBitmapDataR;  // dane bitmapy
    unsigned char   *mBitmapDataG;  // dane bitmapy
    unsigned char   *mBitmapDataB;  // dane bitmapy
    
    CBitmap();
    CBitmap(unsigned long size);    // rozmiar bitmapy
    CBitmap(unsigned long size, char filename[]);
    
    virtual ~CBitmap();

};

#endif // !defined(AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_)

— BitmapMask.cpp
// BitmapMask.cpp: implementation of the CBitmapMask class.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include “BitmapMask.h”

CBitmapMask::CBitmapMask()
{

}

CBitmapMask::~CBitmapMask()
{

    if (mBitmapMaskData!=NULL) free(mBitmapMaskData);

}

CBitmapMask::CBitmapMask(unsigned long size, char filename[])
{

    FILE *bmp_file;

    mBitmapMaskData = (unsigned char *) malloc (size);

    if ((bmp_file=fopen(filename,"rb"))==NULL) MessageBox(0,"error","error",MB_OK);
    fread(mBitmapMaskData,size,1,bmp_file);
    fclose(bmp_file);

}

CBitmapMask::CBitmapMask(unsigned long size)
{
mBitmapMaskData = (unsigned char *) malloc (size);
}

— BitmapMask.h

// BitmapMask.h: interface for the CBitmapMask class.

#if !defined(AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_)
#define AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CBitmapMask
{
public:

    unsigned char   *mBitmapMaskData;

    CBitmapMask();
    CBitmapMask(unsigned long size);        // od razu alokuj pamiec
    CBitmapMask(unsigned long size, char filename[]);       // wczytaj z pliku


    virtual ~CBitmapMask();

};

#endif // !defined(AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_)–
Best regards,
firefox mailto:@palpetine

Tego nie znajdziesz w zadnym sklepie!
[ http://oferty.onet.pl ]

At 15.30 02/01/02 +0100, you wrote:

Hello sdl,
tested under win2k, tnt2/m64/zx/pro, sdl-1.2.3
what is wrong with that code ? wrong shifting ?
please help, because i am getting out of my mind.

To answer your question we should know what effect did you want to get from
this code, if you want a simple conversion you should let sdl doing that
because you cannot really assume how the bits in ANY rgb format are
distributed.

A 16bit format may be RGB or BGR for instance. 24bit format are far more
complex since you can find a lot of different pixel types (RGB, BGR, RGBA,
ARGB…)

SDL offers a call just to do it… SDL_MapRGB

RGB_FROM_RGB565(screen->pixels[h1]>>2,vaddr01->mBitmapMaskData[h1],

vaddr02->mBitmapMaskData[h1],

vaddr03->mBitmapMaskData[h1]);

…your code is also not compilable since you miss this macro definition :slight_smile:

If it’s a simple conversion that you want (and if you intend RGB565 from
RGB and not the opposite) try something like this:

#define RGB565_FROM_RGB(screen,pixel,r,g,b) ((unsigned
short)pixel)=SDL_MapRGB(screen->format,r,g,b)

Bye,
Gabry (gabrielegreco at tin.it)

A 16bit format may be RGB or BGR for instance. 24bit format are far more
complex since you can find a lot of different pixel types (RGB, BGR, RGBA,
ARGB…)

24 bit has no A :slight_smile: 32 bit has one!so for 24, there are the same problems as
16, but with a test you could find out what format they are and set a flag

At 19.38 02/01/2002 +0100, you wrote:

A 16bit format may be RGB or BGR for instance. 24bit format are far more
complex since you can find a lot of different pixel types (RGB, BGR, RGBA,
ARGB…)
24 bit has no A :slight_smile: 32 bit has one!so for 24, there are the same problems as
16, but with a test you could find out what format they are and set a flag

Many boards works only in 32bit also if you ask for 24bpp, so you have to
consider them (at least by checking pitch and BitPerPixel fields of your
video surface). Obviously you can ask SDL the pixel format, ad use tons of
different drawing code for every pixel mode but why you need to reinvent
the wheel?

If speed is important he shouldn’t draw anyway pixel per pixel, or at least
he should do that on a software surface and then blit it to the 16bit screen…

We can’t anyway say that much about what the original poster wants to do
because he doesn’t explained it that well :slight_smile:

Bye,
Gabry

Hello Gabriele,

Wednesday, January 02, 2002, 9:32:41 PM, you wrote:

thanks for all answers.

GG> We can’t anyway say that much about what the original poster wants to do
GG> because he doesn’t explained it that well :slight_smile:

i did truecolor bumpmapping in several ways. i can put it somewhere on ftp, just
tell me where if somebody is intrested. code is very nasty and slow,
but it looks nice ;)–
Best regards,
firefox mailto:@palpetine

Tego nie znajdziesz w zadnym sklepie!
[ http://oferty.onet.pl ]