• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Acharis

Problem with SDL_LoadBMP & glDrawPixels

6 posts in this topic

I have a very simple code:
1) First I load BMP via SDL_LoadBMP (it's BGR)
2) Next I convert it to RBGA and flip (manually, pixel by pixel)
3) Then I display it via glDrawPixels(w,h,GL_RGBA,GL_UNSIGNED_BYTE,image);

The odd thing, everything works fine as long as the image size can be divided by 4... When it is not (like 250x250) it shows quite random results (sometimes colours are messed up, sometimes parts of the image in different parts). I have not touched glPixelsStorage, it should have default values.
0

Share this post


Link to post
Share on other sites
The alignment works per row on byte level, not on pixel level. Since each pixel of your RGBA image has four components, then it by definition must always satisfy the byte alignment (which is 4, since you said the storage parameters have their default values). This can not be the problem under the circumstances you have explained it.

Can you provide screen shots of what the different results look like? I have seen many different cases of "messed up colors" and "different parts" and images to clearly show what you mean would be great,

As a side note, your step 2 is not necessary. OpenGL is very flexible with what parameters you can pass and how color components can be ordered. If you have a BGR image you can pass GL_BGR to glDrawPixels. If you add an alpha channel, you have some options depending on where in the pixel data you put it, but GL_BGRA may be an option.

edit: And of course, make sure that [i]your[/i] code handles [i]SDL's[/i] alignment padding as well. OpenGL is not the only one with alignment requirements. Edited by Brother Bob
1

Share this post


Link to post
Share on other sites
Screenshot:
http://s1165.photobucket.com/albums/q591/LordArchibald/?action=view&current=divby4Error.png
The first rectangle is 250x250, the second is 255x255, the third is 256x256. All should look like the last one.


[quote name='Brother Bob' timestamp='1349718105' post='4988053']
As a side note, your step 2 is not necessary. OpenGL is very flexible with what parameters you can pass and how color components can be ordered. If you have a BGR image you can pass GL_BGR to glDrawPixels. If you add an alpha channel, you have some options depending on where in the pixel data you put it, but GL_BGRA may be an option.[/quote]Yes, I know, but I wanted it to work with very outdated hardware and BGR/BGRA requires higher OpenGL version.

[quote name='Brother Bob' timestamp='1349718105' post='4988053']
edit: And of course, make sure that your code handles SDL's alignment padding as well. OpenGL is not the only one with alignment requirements.
[/quote]Can you explain more? I have never used SDL alignmnent padding (so it should have default values).


BTW, which SDL version exactly are you using and can you drop me a link where you downloaded it from? I used to have a problem with TTF library and it turned out I was caused by using some old and buggy version...
0

Share this post


Link to post
Share on other sites
[quote name='Acharis' timestamp='1349718991' post='4988059']
Screenshot:
[url="http://s1165.photobucket.com/albums/q591/LordArchibald/?action=view&current=divby4Error.png"]http://s1165.photobu...divby4Error.png[/url]
The first rectangle is 250x250, the second is 255x255, the third is 256x256. All should look like the last one.
[/quote]
That is definitely an alignment issue. Solution is likely below.

[quote name='Acharis' timestamp='1349718991' post='4988059'][quote name='Brother Bob' timestamp='1349718105' post='4988053']
As a side note, your step 2 is not necessary. OpenGL is very flexible with what parameters you can pass and how color components can be ordered. If you have a BGR image you can pass GL_BGR to glDrawPixels. If you add an alpha channel, you have some options depending on where in the pixel data you put it, but GL_BGRA may be an option.[/quote]Yes, I know, but I wanted it to work with very outdated hardware and BGR/BGRA requires higher OpenGL version.
[/quote]
It was added to the core API in early 1998, over 14 years ago now. It has even been available as a very common extension since before then. You're the one knowing how old hardware you're willing to deal with, though.

[quote name='Acharis' timestamp='1349718991' post='4988059'][quote name='Brother Bob' timestamp='1349718105' post='4988053']
edit: And of course, make sure that your code handles SDL's alignment padding as well. OpenGL is not the only one with alignment requirements.
[/quote]Can you explain more? I have never used SDL alignmnent padding (so it should have default values).
[/quote]
The SDL_surface structure has a member called [i]pitch[/i] that hold the offset between two consecutive rows of the image. I assume that SDL enforces at least a 4 byte alignment and so if a row is not a multiple of 4 bytes, then you cannot assume that [i]width*3[/i] is equal to [i]pitch[/i] either. You must use the [i]pitch[/i] member to calculate the location of each row in memory, not the width of the image.

[quote name='Acharis' timestamp='1349718991' post='4988059']
BTW, which SDL version exactly are you using and can you drop me a link where you downloaded it from? I used to have a problem with TTF library and it turned out I was caused by using some old and buggy version...
[/quote]
I'm not using SDL.
1

Share this post


Link to post
Share on other sites
What version of SDL are [b]you[/b] using - and [i]where did you download it from[/i]? ([url="http://www.libsdl.org/"]hint[/url])
0

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1349730036' post='4988118']
What version of SDL are [b]you[/b] using - and [i]where did you download it from[/i]? ([url="http://www.libsdl.org/"]hint[/url])
[/quote]SDL 1.2.15 from http://www.libsdl.org/download-1.2.php
SDL_mixer_version - CompiledVersion: 1.2.12 LinkedVersion: 1.2.12 (do not remember where I downloaded it from)
SDL_TTF_version - CompiledVersion:2.0.11 LinkedVersion:2.0.11 (do not remember where I downloaded it from)
0

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1349720279' post='4988066']
That is definitely an alignment issue. Solution is likely below.
[/quote]Yes, that was it. Many thanks!


BTW, if anyone has a comment on the SDL/TTF/Mixer version I'm using, please do so, I already was using a broken TTF library.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0