Color and surfaces problems (source code)

Thank you for your help!!!

Here is the source, ok is almost all commented because I’m trying to port
it
from DOS (watcom C) to Linux.

Ignore comments and Spanish texts.

Only, ginit.cc and rpg.cc are currently on work…
graficos.cc included anyway, headers on gz

Another [OFF-TOPIC]

Where can I find info about [ configure, libtool, etc. ] for easy
distribution (compilation) of my sources?

Thanks again
-------------- next part --------------
// ginit.cpp - Clases de inicializaci?n de los m?dulos
#include “includes/ginit.h”
#include “includes/headers.h”
#include “includes/graficos.h”

#include <SDL.h>
#include <GL/glut.h>
#include <X11/Xlib.h>

//#include “Font.h”

////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR DE CLASE
////////////////////////////////////////////////////////////////////////////////
Maininit::Maininit(char *Iconos,int *main_argc, char *main_argv[]){
//unsigned short *Modo;
//unsigned int count=0;
// SDL_VideoInfo
cout << flush;

Initialized=0;
error=0;
//s_icon=NULL;
//vscreen=NULL;
//int Sexit=0;

///// Set up screen
//screen =(char *) ((VGA_AREA) << 4);
//tscreen =(char *) ((TEXT_AREA) << 4); // Puntero a la pantalla texto
//old_modo_video = 0x3;
//modo_video = 0x3;

//clrscr();
//memmove((void *)tscreen,(void *)INITSTRING,INITSTRING_LENGTH);
cout << “\n Inicializando…”;

//// Compueba la memoria
/*
cout << “\n —===[ Verificando espacio en memoria ]===—” << flush;

Pmem_info(&Meminfo,0);
memoria=Meminfo.LargestBlockAvail;
if(Meminfo.LargestBlockAvail<640000) {
cout << “\n No hay memoria suficiente… (ginit.cpp)” << flush;
error=1;
return;
}else
printf("\n Memoria disponible: %u\n",Meminfo.LargestBlockAvail);
Initialized|=MAININIT_MEMORIA;
*/
//// Ya se sabe

cout << “\n —===[ Inicializando Graficos y zonas de memoria ]===—”;
cout << “\n Inicializando sistema grafico.”;
cout << “\n Inicializando Video (SDL).\n”;

if( SDL_Init(SDL_INIT_VIDEO) < 0){
cout << " Error inicializando sistema de video\n";
error=1;
return;
}else
cout << " Sistema de video inicializado\n";

//atexit(SDL_Quit);

/*
cout << “\n Inicializando MESAGL y GLUT.\n”;

glutInit( main_argc, main_argv );
glutInitDisplayMode( GLUT_RGB );
glutCreateWindow(main_argv[0]);

cout << " Version de GL : " << (char *) glGetString(GL_VERSION) << “\n” ;
cout << " Extensiones GL : " << (char *) glGetString(GL_EXTENSIONS) << “\n”;
cout << " Render GL : " << (char *) glGetString(GL_RENDERER) << “\n”;
cout << " Distribuidor GL: " << (char *) glGetString(GL_VENDOR) << “\n”;
cout << " Version GLU : " << (char *) gluGetString((enum GLenum)GLU_VERSION) << “\n”;
cout << " Extensiones GLU : " << (char *) gluGetString((enum GLenum)GLU_EXTENSIONS) << “\n”;
cout << " Version API GLUT : " << GLUT_API_VERSION << “\n”;
#ifdef GLUT_XLIB_IMPLEMENTATION
cout << "Xlib Glut Implementacion: " << GLUT_XLIB_IMPLEMENTATION << “\n”;
#endif

*/

//cout << "\n Guardando paleta de colores… ";
//grab_pal();
//Initialized|=MAININIT_PALETA;

/*
if(!get_vesa_info(&VESA,(int)2)){
cout << “\n Vesa no disponible, no se pueden inicializar los graficos (ginit.cpp)”<< flush;
error=2;
getch();
return;
}else{
cout << “\n Vesa Disponible”;
cout << "\n Version: " << hex << VESA.VbeVersion << dec;
cout << "\n OEM: " << (char *)MAKE_PM(VESA.OemStringPtr) << flush;

if(VESA.VbeVersion<0x0200){
cout << “\n ERROR: Vesa 2.00 o superior requerido para ejecutar el programa (ginit.cpp)” << flush;
error=3;
return;
}

Modo=(unsigned short *)MAKE_PM(VESA.VideoModePtr);

while((*Modo != 0xFFFF) && (*Modo!=VESA_GRAFICO))Modo++;
if(*Modo == 0xFFFF){
cout << “\n Inicializaci?n del modo " << VESA_GRAFICO << " NO soportada” << flush;
error=4;
return;
}
cout << “\n Modo " << (unsigned short)Modo << " soportado";
cout << "\n Memoria total: " << (unsigned long)(VESA.TotalMemory
64) << " KB” << flush;
}

if(!get_vesa_mode_info(&Modei,VESA_GRAFICO)){
cout << “\n Error obteniendo infomacion sobre el VESA” << flush;
error=5;
getch();
return;
}

flat_buffer=(long)Modei.PhysBasePtr; // Direcci?n de la
// memoria lineal
cout << “\n Inicializando vscreen.”;
tama?o_vscreen=Modei.Xres*Modei.Yres;
cout << “\n Reservando " << tama?o_vscreen << " bytes…”<< flush;

vscreen= new char[tama?o_vscreen];

if(vscreen==NULL){
cout << “\n Error al asignar memoria para el vbuffer (ginit.cpp)” << flush;
error=6;
getch();
return;
}

Initialized|=MAININIT_VESA;
cout << “\n Inicializando VESA terminada.”;

cout << “\n Cargando gr?ficos del sistema…” << flush;

load_spr_standard(Iconos);
if(error){
cout << "\n Error cargando gr?ficos. error: " << error << flush;
getch();
return;
}
*/
cout << “\n Cargados los gra?ficos del sistema…” << flush;

//botones.primero=NULL;
//botones.last_button=0;
//botones.nobotones=0;

cout << “\n —===[ Controlador del rat?n ]===—” << flush;
cout << "\n —===[ Inicializando Tarjeta de Sonido ]===— ";
cout << “\n Sin sonido…\n”;
cout << “\n Inicializacion completada… Pulse cualquier tecla…\n”;

cout << "\n Entrando en modo grafico… " << flush;

screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE);

//init_x(0,0,800,600,“TEST”);

if ( screen == NULL ) {
cout << stderr << "No puedo inicializar el modo grafico: " << SDL_GetError();
return;
}

/*
Local_Default_Depth = screen->format->BytesPerPixel;
Local_Default_Width = screen ->w;
Local_Default_Height = screen ->h;
*/

if ( SDL_MUSTLOCK(screen) )
cout << “Debe ser bloqueada”;
else
cout << “No debe ser bloqueada”;
cout << flush;

SDL_WM_SetCaption ( “Rpg - La aventura definitiva…”, “Hola 2” );

return;
};

////////////////////////////////////////////////////////////////////////////////
// DESTRUCTOR DE LA CLASE
////////////////////////////////////////////////////////////////////////////////
Maininit::~Maininit(void){
#ifdef DEBUG
cout << "\n [Destuctor Maininit] ";
#endif

SDL_Quit();
cout << “\n SDL finalizado”;

if(modo_video!=TEXTO){
// set_mode(TEXTO);
#ifdef DEBUG
cout << “\n Modo texto inicializado” << flush;
#endif
}
/*
if(Initialized&MAININIT_VESA){
if(Initialized&MAININIT_VESA_SET){
close_vesa_mode((long)screen);
#ifdef DEBUG
cout << “\n Video desinicializado” << flush;
#endif
Initialized&=~MAININIT_VESA_SET;
}
if(vscreen != NULL){
delete [] vscreen;
vscreen=NULL;
#ifdef DEBUG
cout << “\n Virtual framebuffer desinicializado” << flush;
#endif
}
Initialized&=~MAININIT_VESA;
#ifdef DEBUG
cout << “\n VESA off” << flush;
#endif
}
/
/

if(Initialized&MAININIT_MEMORIA){
Initialized&=~MAININIT_MEMORIA;

#ifdef DEBUG
cout << “\n Memoria Ok” << flush;
#endif
}

if((Initialized&MAININIT_ICONOS) && (s_icon!=NULL)){
Initialized&=~MAININIT_ICONOS;
delete [] s_icon;
s_icon=NULL;
#ifdef DEBUG
cout << “\n Iconos descargados” << flush;
#endif
}

if(Initialized&MAININIT_PALETA){
// putpal(old_paleta);
// cout << “\n Paleta OK”;
Initialized&=~MAININIT_PALETA;
}

if(Initialized&MAININIT_RATON){
delete Main_Mouse;
Initialized&=~MAININIT_RATON;
}
*/
#ifdef DEBUG
cout << "\n [Fin Destuctor Maininit] " << flush;
#endif
return;
};

-------------- next part --------------
////////////////////////////////////////////////////////////////////////////////
// RPG.CPP - Archivo principal y bucle del juego. Se encarga de inicializar la
// memoria y todo lo demas
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
#include “includes/headers.h”
#include “includes/ginit.h”
#include <magick/magick.h>

#if defined(__cplusplus) || defined(c_plusplus)
#undef class
#endif

////////////////////////////////////////////////////////////////////////////////
//
// RPG - Una creacion de Gonzalo A.D.
// Funciona bajo Linux 2.0.36, y gcc 2.7.2.3
//
//
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////

//extern “C” int Main_Menu(void);

////////////////////////////////////////////////////////////////////////////////
// Funciones del juego (Cada una de las partes del juego)
////////////////////////////////////////////////////////////////////////////////

//int FilterEvents(const SDL_Event event) {
/// if ( event->type == SDL_MOUSEMOTION ) {
// return(0); /
Drop it, we’ve handled it */
// }
// return(1);
//}

////////////////////////////////////////////////////////////////////////////////
// MAIN
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]){
int seleccion=0;
int estado;
FILE *fp;
char opcion;
SDL_Surface *nueva_sur;
SDL_Event event;
unsigned int i,j,contador;

Image *Portada;
ImageInfo image_info;

Maininit Main_status(“graficos/iconos.raw”,&argc,argv);

if(Main_status.error){
cout << flush << "\n Error de inicializacion: "<< (int)Main_status.error << flush;
return(1);
}

/* Ahora comienza el test de libpng */

GetImageInfo(&image_info);
(void) strcpy(image_info.filename,“Graficos/Portada.png”);
Portada=ReadImage(&image_info);

if (Portada == (Image *) NULL){
cout << “\n Error al cargar la imagen” << fflush;
return(0);
}

cout << "\nDither : " << image_info.dither << " monocromo: " <<
image_info.monochrome << fflush;

//cout << "\nSize : " << *image_info.size << fflush;

cout << "\n Filesize: " << Portada->filesize << " comments: " <<
Portada->comments << fflush;

cout << "\n Columnas: " << Portada->columns << " filas: " << Portada->rows
<< " depth: " << Portada->depth;
cout << "\n Colores: " << Portada->total_colors;
cout << "\n Xres: " << Portada->x_resolution << " Yres: " <<
Portada->y_resolution;
cout << fflush;
cout << "\n Packets: " << Portada->packets << " Size : " <<
Portada->packet_size << fflush;

nueva_sur = SDL_CreateRGBSurface (SDL_SWSURFACE,800,600,16,0xff0000,0xff00,0xff,0);

cout << “\n Bytes por pixel” << nueva_sur->format->BytesPerPixel << fflush;

for(i=0;i<800*600;i+=3){
*((char *)nueva_sur->pixels+i)=100;

}

SDL_BlitSurface(nueva_sur,NULL,Main_status.screen,NULL);
//SDL_Delay(5000);
SDL_FreeSurface(nueva_sur);

SDL_Flip(Main_status.screen);
DestroyImage(Portada);

SDL_Delay(5000);

/*
while(1){

seleccion=Main_Menu();

switch(seleccion){

case 1:

// Create_JPG();
break;

case 2:

// if(!Start_New())
// Kill(“Hubo error en m?dulo Start_New”);
break;

case 3:
break;

case 4:

// Quit("\n Ok todo bien");
break;
}
break;
}
/
// Fin del programa main()
/

SDL_Delay(1000);
SDL_SetEventFilter(FilterEvents);

   while ( SDL_WaitEvent(&event) ) {
   	  switch (event.type) {
                    case SDL_ACTIVEEVENT: {
                            if ( event.active.state & SDL_APPACTIVE ) {
                                    if ( event.active.gain ) {
                                            cout << "App activated\n"<<flush;
                                    } else {
                                            cout << "App iconified\n" << flush;
                                    }
                            }
                    }
                    break;
                                    
                    case SDL_MOUSEBUTTONDOWN: {
                            Uint8 *keys;

                            keys = SDL_GetKeyState(NULL);
                            if ( keys[SDLK_ESCAPE] == SDL_PRESSED ) {
                                    cout << "Bye bye...\n" << flush;
                                    return(0);
                            }
                            cout << "Mouse button pressed\n" <<flush;
                    }
                    break;

                    case SDL_QUIT: {
                            cout << "Quit requested, quitting.\n"<<flush;
                            return(0);
                    }
                    break;

                    default: 
                    	cout << (int) event.type << flush ;
                    break;
            }
    }

*/
cout << “\n\nFin del programa”;
cout << "\n seleccion: " << seleccion << flush;
return(1);
};

-------------- next part --------------
// graficos.c - rutinas de apollo gr?fico
#include “includes/headers.h”
#include “includes/graficos.h”
#include <string.h>

////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR
////////////////////////////////////////////////////////////////////////////////
Obj_Grafico::Obj_Grafico(void){
#ifdef DEBUG
cout << "\n [Constructor Obj_Grafico] ";
#endif
alto=0;
ancho=0;
tipo=0;
grab_x=0;
grab_y=0;
grab_buffer=NULL;
#ifdef DEBUG
cout << "\n [Fin Constructor Obj_Grafico] ";
#endif
return;
};

////////////////////////////////////////////////////////////////////////////////
// DESTRUCTOR
////////////////////////////////////////////////////////////////////////////////
Obj_Grafico::~Obj_Grafico(void){
#ifdef DEBUG
cout << "\n [Destructor Obj_Grafico] ";
#endif
alto=0;
ancho=0;
tipo=0;
grab_x=0;
grab_y=0;
if(grab_buffer != NULL){
delete [] grab_buffer;
#ifdef DEBUG
cout << “\n Desinicializando Grab_Buffer”;
#endif
grab_buffer=NULL;
}
#ifdef DEBUG
cout << "\n [Fin Destructor Obj_Grafico]\n ";
#endif
return;
};

////////////////////////////////////////////////////////////////////////////////
// grab - Salva parte de la memoria en un buffer
////////////////////////////////////////////////////////////////////////////////
void Obj_Grafico::grab(char where,int x, int y){
int i;
grab_x=x;
grab_y=y;
grab_buffer = new char[ancho
alto];
if(grab_buffer == NULL) return;

for(i=0;i<alto;i++,y++)
    memmove(grab_buffer+ancho*i,where+y*800+x,ancho);

return;
};

////////////////////////////////////////////////////////////////////////////////
// ungrab - Restaura el buffer
////////////////////////////////////////////////////////////////////////////////
void Obj_Grafico::ungrab(char where){
int i;
if(grab_buffer!=NULL){
for(i=0;i<alto;i++,grab_y++)
memmove(where+grab_y
800+grab_x,grab_buffer+ancho*i,ancho);
delete [] grab_buffer;
grab_buffer = NULL;
}
return;
};

////////////////////////////////////////////////////////////////////////////////
// putpal - coloca la paleta grafica en la memoria de video
// Nota: Hace desplazamiento del bios (>> 2)
////////////////////////////////////////////////////////////////////////////////
/*
void Obj_Grafico::putpal(char *paleta){
int i;
outp(0x3c8, 0);
for(i=0; i<768; i++)
outp(0x3c9,paleta[i] >> 2);
return;
};

*/

////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR DE LA CLASE
////////////////////////////////////////////////////////////////////////////////
Picture::Picture(char *Archivo_RAW){
Picture_Initialized=0;
error=0;

#ifdef DEBUG
cout << "\n [Constructor Picture] ";
#endif

ancho=0;
alto=0;
buffer=NULL;
cout << "\n Cargando archivo " << (char *)Archivo_RAW << flush;
//loadpic(Archivo_RAW);
if(error){
cout << “\n Error cargando archivo (graficos.cpp)” << flush;
return;
}

#ifdef DEBUG
cout << "\n [Fin Constructor Picture] " << flush;
#endif

return;
};

////////////////////////////////////////////////////////////////////////////////
// DESTRUCTOR DE LA CLASE
////////////////////////////////////////////////////////////////////////////////
Picture::~Picture(void){

ancho=0;
alto =0;

#ifdef DEBUG
cout << "\n [Destructor Picture] ";
#endif

if((Picture_Initialized&PICTURE_BUFFER) && (buffer != NULL)){
cout << “\n Liberando buffer del grafico”;
delete [] buffer;
buffer=NULL;
Picture_Initialized=0;
}
if(error) cout << "\n Hubo error del tipo " << error;
error=0;

#ifdef DEBUG
cout << "\n [Fin Destructor Picture] ";
#endif

return;
};

////////////////////////////////////////////////////////////////////////////////
// put_pic - Muestra un gr?fico en la pantalla
////////////////////////////////////////////////////////////////////////////////
/*
void Picture::put_pic(int x,int y,char *dest){
unsigned register int i;
unsigned int pic_ancho=ancho;
unsigned int pic_alto=alto;
char *s_point=(char )dest+y800+x;
char *data;
//putpal(pic_paleta);
data=buffer;

for(;pic_alto>0;pic_alto–,s_point+=800)
for(i=0;i<pic_ancho;i++)
if(data!=0)(s_point+i)=*(data++);
else data++;
return;
};
*/

////////////////////////////////////////////////////////////////////////////////
// loadpic - abre archivo, carga la cabecera, paleta, actualiza el registro
// y carga la imagen en el buffer.
////////////////////////////////////////////////////////////////////////////////
/*
void Picture::loadpic(char *archivo){
int file;
char cabecera[32];

if((file=open(archivo,O_RDONLY | O_BINARY))==-1){
cout << "\n Error abriendo archivo " << (char *)archivo << flush;
error=ERROR_ABRIR_ARCHIVO;
return;
}

if(read(file,cabecera, 32)==-1){
cout << "\n Error leyendo archivo " << (char *)archivo << flush;
error=ERROR_LEER_ARCHIVO;
close(file);
return;
}

// Calcula el tama?o
ancho=((int)cabecera[8]<<8) | (0x00FF&cabecera[9]);
alto=(cabecera[10]<<8) | (0x00FF&cabecera[11]);

// Coge memoria

buffer= new char[ancho*alto];

if(buffer == NULL ){
error=ERROR_NOMEM;
close(file);
return;
}

Picture_Initialized|=PICTURE_BUFFER;

// Lee la paleta
if(read(file,pic_paleta, 768)==-1){
error=ERROR_LEER_ARCHIVO;
close(file);
return;
}

Picture_Initialized|=PICTURE_PALETA;

if(read(file,buffer,ancho*alto)==-1){
error=ERROR_LEER_ARCHIVO;
close(file);
return;
}

Picture_Initialized|=PICTURE_GRAFICO;

close(file);
error=0;
return;
};
*/
-------------- next part --------------
A non-text attachment was scrubbed…
Name: includes.tar.gz
Type: application/x-gzip
Size: 2819 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/19991218/f45289ac/attachment.bin