|
*** advanced function
Used to access the texture memory directly
for mass changes this approach is much faster then using STATE_bitmap_set_pixel()
The function can only be called after at least one render was done.
Note that after you finish reading /writing to the bitmap memory you need to call
Parameters:
bitmap_handle [IN]:
The bitmap we want to access its memory
mipmap_level [IN]:
See details in STATE_bitmap_set_pixel()
memory_ptr [OUT]:
a pointer to the first BYTE of the bitmap memory
number_of_bytes_per_pixel [OUT]:
returns the size in bytes of a pixel for example
returns 4 for 32 bit formats such as BITMAP_FORMAT_A8R8G8B8
NOTE that when using non standard formats the function will return 0
this doesn't mean that one cant access the bitmap memory, it just
means that you will have to figure the size yourself.
You do it according the format you set when you called
STATE_bitmap_set_default_format(). For example if called STATE_bitmap_set_default_format(BITMAP_FORMAT_A8R8G8B8);
at the beginning of your program, you know that the texture format is 32 bit (4 bytes per pixel)
number_of_pixels_in_one_line [OUT]
This is the same value as returned by STATE_bitmap_get_width()
number_of_lines [OUT]
This is the same value as returned by STATE_bitmap_get_height()
Return value:
OK or VR_ERROR. VR_ERROR is returned when directly accessing the bitmap memory memory failed.
Remarks:
Delphi programers should use STATE_bitmap_write_memory_block() instead.
Example:
In this example we will access all the pixels of the texture and make them one shade brighter
Bitmaps memory can only be accessed after after we had at least one call to STATE_engine_render() during the program run
STATE_engine_render(NULL, NULL);
STATE_bitmap_set_default_format(BITMAP_FORMAT_A8R8G8B8);
DWORD my_bitmap=STATE_bitmap_load("picture.jpg", -1);
STATE_polygon_set_bitmap_fill(my_polygn, my_bitmap);
STATE_polygon_use_mipmap(my_polygn, NO); make sure that only mipmap level 0 is used
make_bitmap_brighter(my_bitmap);
Here is the implementation of the make_bitmap_brighter() function
int make_bitmap_brighter(DWORD my_bitmap)
{
BYTE *mem_ptr=NULL;
int number_of_bytes_per_pixel;
int number_of_pixels_in_one_line;
int number_of_lines;
STATE_bitmap_start_direct_memory_access(my_bitmap, 0,&mem_ptr, &number_of_bytes_per_pixel, &number_of_pixels_in_one_line, &number_of_lines);
if(mem_ptr==NULL) {
error_msg();
return(VR_ERROR);
}
if(number_of_bytes_per_pixel!=4)
return(VR_ERROR); In this simple example we assume we loaded the texture in BITMAP_FORMAT_A8R8G8B8 see STATE_bitmap_set_default_format() for more details
BYTE *line_start=mem_ptr;
for(int line=0; line
|