Odp: OpenGL building texture from sdl surface

i decided to stick with ogl 1.1 (ok i didn’t decide i just couldn’t find a
newer interface ;()

anyway i’m new to programing c++ and all that stuff… i did this:

char *bytes = (char *)sdl_surface->pixels;
char tmp;
int size = sdl_surface->w * sdl_surface->h;
for (int s=0; s<size; s+=3)
{
tmp = bytes[s];
bytes[s] = bytes[s+2];
bytes[s+2] = tmp;
}

and it makes the nehe logo blueish to around 2/3 of it the rest still looks
like bgr… so i guess i did something stupid in counting the num of bytes,
size …
it’s not as simple as w * h?

please help me out !

pozdroofki
gz.

apologies for posting stupid questions and bad english…

bytesize should be: width * height * 3;

pozdroofki
gz…

i decided to stick with ogl 1.1 (ok i didn’t decide i just couldn’t
find a newer interface ;()

anyway i’m new to programing c++ and all that stuff… i did this:

char *bytes = (char *)sdl_surface->pixels;
char tmp;
int size = sdl_surface->w * sdl_surface->h;

Well, assuming that the surface pitch equals w*BytesPerPixel (which is
not a safe assumption!), this is correct…

for (int s=0; s<size; s+=3)

…but this isn’t. You’re terminating the loop after processing w*h
bytes, while you should count pixels. :slight_smile:

[…]

it’s not as simple as w * h?

Returning to that; no, it’s not always wh. You should make it a habit to
use surface->pitch instead of w * BytesPerPixel to index along the Y
axis. Also, don’t access any skipped bytes between the end of a row
(w
BytesPerPixel) and the first pixel of the next row - weird things may
happen.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 26 October 2001 22:45, grzesio furga wrote: