# Changing surface formats

**URL:** <https://discourse.libsdl.org/t/changing-surface-formats/2584>\
**Category:** SDL Development\
**Created:** [June 8, 2000, 12:01am UTC](https://discourse.libsdl.org/t/changing-surface-formats/2584 "2000-06-08T00:01:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Ramsay](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/65b543/32.png) [@Frank\_Ramsay](https://discourse.libsdl.org/u/Frank_Ramsay)\
**Post date:** [June 8, 2000, 12:01am UTC](https://discourse.libsdl.org/t/changing-surface-formats/2584/1 "2000-06-08T00:01:00Z")

</div>

I need to take a SDL\_Surface object and convert it to  
a 32bpp formatI know I can use SDL\_ConvertSurface(…) to actually  
convert the surface however I need to create and SDL\_PixelFormat  
object and I’m not sure how to populate it.

So assuming I have the variable:  
SDL\_PixelFormat pixFmt;  
I would guess that pixFmt.pallette could be NULL (since it’s a 32bpp  
surface)  
pixFmt.BitsPerPixel = 32; // let us assume the surface is RGBA format  
and  
pixFmt.BytesPerPixel = 4;

but what about the Rloss, Rshift, Rmask (and their G and B cousins)?

I would guess that the colorkey and alpha could be 0 since I’m not going  
to be using them.

```
		-fjr-- 

```

Frank J. Ramsay  
@Frank_Ramsay

---

<div class="post-metadata">

**Author:** ![Frank\_Ramsay](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/65b543/32.png) [@Frank\_Ramsay](https://discourse.libsdl.org/u/Frank_Ramsay)\
**Post date:** [June 8, 2000, 2:13am UTC](https://discourse.libsdl.org/t/changing-surface-formats/2584/2 "2000-06-08T02:13:37Z")

</div>

Frank Ramsay wrote:

> 

never mind…  
I realized how I could do this.

```
	-fjr-- 

```

Frank J. Ramsay  
@Frank_Ramsay

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [June 8, 2000, 3:48am UTC](https://discourse.libsdl.org/t/changing-surface-formats/2584/3 "2000-06-08T03:48:40Z")

</div>

> Frank Ramsay wrote:
> 
> > 
> 
> never mind…  
> I realized how I could do this.

How? 🙂  
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

---

<div class="post-metadata">

**Author:** ![Frank\_Ramsay](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/65b543/32.png) [@Frank\_Ramsay](https://discourse.libsdl.org/u/Frank_Ramsay)\
**Post date:** [June 8, 2000, 4:23am UTC](https://discourse.libsdl.org/t/changing-surface-formats/2584/4 "2000-06-08T04:23:01Z")

</div>

Sam Lantinga wrote:

> > Frank Ramsay wrote:
> > 
> > > 
> > 
> > never mind…  
> > I realized how I could do this.
> 
> How? 🙂  
> -Sam Lantinga, Lead Programmer, Loki Entertainment Software

well like this…

SDL\_Surface \*theScreen = SDL\_SetVideoMode(VIEW\_WIDTH, VIEW\_HEIGHT, 32,  
SDL\_DOUBLEBUF)  
SDL\_Surface \*tmpSurface = SDL\_LoadBMP(argv[1]);  
SDL\_Surface \*panoSurfaceRaw = SDL\_DisplayFormat(tmpSurface);

It’s not the best way, but it works for now.

```
	-fjr-- 

```

Frank J. Ramsay  
@Frank_Ramsay
