flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > sdl output in fasm?

Author
Thread Post new topic Reply to topic
Matrix



Joined: 04 Sep 2004
Posts: 1008
Location: Overflow
sdl output in fasm?
Ok guys,
so this is what i found without any hacking now that is closest to dos graphic screen buffer rendering:

(the other one i found is xvideo -for x-window system- that is somewhat similar but said to be hard to be used in asm..., another one is /dev/fb but that looks like to get more and more phased out...)

windowed test:

Code:

#include <SDL/SDL.h>                          
#include <stdio.h>                            
#include <stdlib.h>                           
Uint16 CreateHicolorPixel(SDL_PixelFormat * fmtUint8 red,
Uint8 greenUint8 blue)                                   
{                                                          
Uint16 value;                                              
/* This series of bit shifts uses the information from the 
SDL_Format structure to correctly compose a 16-bit pixel   
value from 8-bit redgreenand blue data. */             
value = ((red >> fmt->Rloss) << fmt->Rshift) +             
((green >> fmt->Gloss) << fmt->Gshift) +                   
((blue >> fmt->Bloss) << fmt->Bshift);                     
return value;                                              
}                                                          
int main()                                                 
{                                                          
SDL_Surface *screen;                                       
Uint16 *raw_pixels;                                        
int xy;                                                  

/* Initialize SDL’s video system and check for errors. */
if (SDL_Init(SDL_INIT_VIDEO!0) {                     
printf("Unable to initialize SDL: %s\n"SDL_GetError());
return 1;                                                
}                                                        
/* Make sure SDL_Quit gets called when the program exits! */
atexit(SDL_Quit);                                           
/* Attempt to set a 256x256 hicolor (16-bitvideo mode.    
This will set some type of 16-bit modebut we won’t        
know which particular pixel format ahead of time. If        
the video card can’t handle hicolor modesSDL will         
emulate it. */                                              
screen = SDL_SetVideoMode(256256160);                 
if (screen == NULL) {                                       
printf("Unable to set video mode: %s\n"SDL_GetError());   
return 1;                                                   
}                                                           
/* Video memory can be strangeand it’s sometimes necessary to
"lock" it before it can be modified. SDL abstracts this with   
the SDL_LockSurface function. */                               
SDL_LockSurface(screen);                                       
/* Get a pointer to the video surface’s memory. */             
raw_pixels = (Uint16 *) screen->pixels;                        
/* We can now safely write to the video surface. We’ll draw a  
nice gradient pattern by varying our red and blue components   
along the X and Y axes. Notice the formula used to calculate
the offset into the framebuffer for each pixel.
(The pitch is the number of bytes per scanline in memory.) */
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
x0y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;


}
}
/* We’re finished drawingso unlock the surface. */
SDL_UnlockSurface(screen);
/* Inform SDL that the screen has been changed. This is
necessary because SDL’s screen surface is not always the real
framebuffer; it is sometimes emulated behind the scenes. */
SDL_UpdateRect(screen0000);
/* Pause for a few seconds as the viewer gasps in awe. */
SDL_Delay(3000);
return 0;
}



fullscreen test:

Code:

#include <SDL/SDL.h>                      
#include <stdio.h>                        
#include <stdlib.h>                       
int main()                                
{                                         
SDL_Surface *screen;                      
/* Initialize SDL’s video system and check for errors */
if (SDL_Init(SDL_INIT_VIDEO!0) {                    
printf("Unable to initialize SDL: %s\n"SDL_GetError());
return 1;                                                
}                                                        
/* Make sure SDL_Quit gets called when the program exits! */
atexit(SDL_Quit);                                           
/* Attempt to set a 640x480 hicolor video mode */           
screen = SDL_SetVideoMode(64048016SDL_FULLSCREEN);    
if (screen == NULL) {                                       
printf("Unable to set video mode: %s\n"SDL_GetError());   
return 1;                                                   
}                                                           
/* If we got this fareverything worked */                 
printf("Success!\n");                                       

/* Example of direct pixel access with SDL. */
Uint16 CreateHicolorPixel(SDL_PixelFormat * fmtUint8 red,
Uint8 greenUint8 blue)                                   
{                                                          
Uint16 value;                                              
/* This series of bit shifts uses the information from the 
SDL_Format structure to correctly compose a 16-bit pixel   
value from 8-bit redgreenand blue data. */             
value = ((red >> fmt->Rloss) << fmt->Rshift) +             
((green >> fmt->Gloss) << fmt->Gshift) +                   
((blue >> fmt->Bloss) << fmt->Bshift);                     
return value;                                              
}                                                          

Uint16 *raw_pixels;
int xyi;       

/*Video memory can be strangeand it’s sometimes necessary to
"lock" it before it can be modified. SDL abstracts this with  
the SDL_LockSurface function. */                              
SDL_LockSurface(screen);                                      
/* Get a pointer to the video surface’s memory. */            
raw_pixels = (Uint16 *) screen->pixels;                       
/* We can now safely write to the video surface. We’ll draw a 
nice gradient pattern by varying our red and blue components  
along the X and Y axes. Notice the formula used to calculate  
the offset into the framebuffer for each pixel.               
(The pitch is the number of bytes per scanline in memory.) */ 
for (i = 0; i < 400; i+=4) {                                  
for (x = 0; x < 640; x++) {
for (y = 0; y < 480; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
round ((sin ((y+i)*(3.14159/(480+i))))*200), round ((sin ((i+x)*(3.14159/(640+i))))*200), round ((sin ((y+x+i)*(3.14159/(480+x+y+i))))*200));
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;

}
}
/*SDL_Delay(10);*/

/* We’re finished drawingso unlock the surface. */
SDL_UnlockSurface(screen);
/* Inform SDL that the screen has been changed. This is
necessary because SDL’s screen surface is not always the real
framebuffer; it is sometimes emulated behind the scenes. */
SDL_UpdateRect(screen0000);
/* Pause for a few seconds as the viewer gasps in awe. */
}
SDL_Delay(3000);
return 0;
}




to compile you need to do:

Code:

gcc sdltest.c -o sdltest `sdl-config --cflags --libs`




anyone willing to help port it to be used with FASM?
Post 03 Nov 2011, 14:40
View user's profile Send private message Visit poster's website Reply with quote
pippi



Joined: 29 Oct 2009
Posts: 2
Another C library that might interest you: TinyPTC
Post 08 Nov 2011, 04:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2013, Tomasz Grysztar.