Png image SDL/OpenGL

Hi
can u find out why I cannot see the image? I’m stuck…
Many thanks
Michael----------

/// Texture stuff
#define MAX_TEXTURES 4
#define PANEL_FILENAME “Images/pnl.png”
#define PANEL_TEXTURE 0

int LoadGLTexture(char *pFileName, int TextureId)
{
int Stat = FALSE;
char TextureFileName[255];

/// Need to get the actual texture path
/// and append the filename to it.
strcpy(TextureFileName, gPluginDataFile);
strcat(TextureFileName, pFileName);

sprintf(debugStr,"### - LoadGLTexture() - loading: %s\n", TextureFileName);
XPLMDebugString(debugStr);

SDL_Surface *image; // This surface will tell us the details of the image

    image = IMG_Load(TextureFileName);

if (image) {

//the XPLM functions are equivalent to OpenGL
XPLMGenerateTextureNumbers(&gTexture[TextureId], 1);
XPLMBindTexture2d(gTexture[TextureId], 0);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h, GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	Stat = TRUE;

} else {
	XPLMDebugString("### LoadGLTexture(): Error loading texture!\n");
	Stat = FALSE;
}

if ( image ) {
SDL_FreeSurface( image );
}
return Stat;
}

/// Draws the textures that make up the gauge
int DrawGLScene(float x1, float y1)
{
glPushMatrix();
XPLMBindTexture2d(gTexture[PANEL_TEXTURE], 0);
glBegin(GL_QUADS);
glTexCoord2f(1, 0.0f); glVertex2f(PanelRight, PanelBottom); // Bottom Right
Of The Texture and Quad
glTexCoord2f(0, 0.0f); glVertex2f(PanelLeft, PanelBottom); // Bottom Left
Of The Texture and Quad
glTexCoord2f(0, 1.0f); glVertex2f(PanelLeft, PanelTop); // Top Left Of The
Texture and Quad
glTexCoord2f(1, 1.0f); glVertex2f(PanelRight, PanelTop); // Top Right Of The
Texture and Quad
glEnd();

glPopMatrix();

Try this
SDL_Surface *tmp; // This surface will tell us the details of the image
tmp = IMG_Load(TextureFileName);
SDL_Surface *img = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org]
On Behalf Of Michael
Sent: Wednesday, July 15, 2009 5:27 PM
To: sdl at libsdl.org
Subject: [SDL] png image SDL/OpenGL

Hi
can u find out why I cannot see the image? I’m stuck…
Many thanks
Michael

/// Texture stuff
#define MAX_TEXTURES 4
#define PANEL_FILENAME “Images/pnl.png”
#define PANEL_TEXTURE 0

int LoadGLTexture(char *pFileName, int TextureId)
{
int Stat = FALSE;
char TextureFileName[255];

/// Need to get the actual texture path
/// and append the filename to it.
strcpy(TextureFileName, gPluginDataFile);
strcat(TextureFileName, pFileName);

sprintf(debugStr,"### - LoadGLTexture() - loading: %s\n",
TextureFileName);
XPLMDebugString(debugStr);

SDL_Surface *image; // This surface will tell us the details of
the image

    image = IMG_Load(TextureFileName);

if (image) {
//the XPLM functions are equivalent to OpenGL
XPLMGenerateTextureNumbers(&gTexture[TextureId], 1);
XPLMBindTexture2d(gTexture[TextureId], 0);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h,
GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

  Stat = TRUE;

} else {
XPLMDebugString("### LoadGLTexture(): Error loading
texture!\n");
Stat = FALSE;
}
if ( image ) {
SDL_FreeSurface( image );
}
return Stat;
}

/// Draws the textures that make up the gauge
int DrawGLScene(float x1, float y1)
{
glPushMatrix();
XPLMBindTexture2d(gTexture[PANEL_TEXTURE], 0);
glBegin(GL_QUADS);
glTexCoord2f(1, 0.0f); glVertex2f(PanelRight, PanelBottom);
// Bottom Right
Of The Texture and Quad
glTexCoord2f(0, 0.0f); glVertex2f(PanelLeft, PanelBottom);
// Bottom Left
Of The Texture and Quad
glTexCoord2f(0, 1.0f); glVertex2f(PanelLeft, PanelTop); // Top
Left Of The
Texture and Quad
glTexCoord2f(1, 1.0f); glVertex2f(PanelRight, PanelTop);
// Top Right Of The
Texture and Quad
glEnd();

glPopMatrix();

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Are you flushing/swapping the buffers?

Jonny DOn Wed, Jul 15, 2009 at 6:32 AM, Hieu Le Trung wrote:

Try this
SDL_Surface *tmp; // This surface will tell us the details of the image
tmp = IMG_Load(TextureFileName);
SDL_Surface *img = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);

-----Original Message-----
From: sdl-bounces at lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org]
On Behalf Of Michael
Sent: Wednesday, July 15, 2009 5:27 PM
To: sdl at libsdl.org
Subject: [SDL] png image SDL/OpenGL

Hi
can u find out why I cannot see the image? I’m stuck…
Many thanks
Michael

/// Texture stuff
#define MAX_TEXTURES 4
#define PANEL_FILENAME “Images/pnl.png”
#define PANEL_TEXTURE 0

int LoadGLTexture(char *pFileName, int TextureId)
{
? ? ? ?int Stat = FALSE;
? ? ? ?char TextureFileName[255];

? ? ? ?/// Need to get the actual texture path
? ? ? ?/// and append the filename to it.
? ? ? ?strcpy(TextureFileName, gPluginDataFile);
? ? ? ?strcat(TextureFileName, pFileName);

? ? ? ?sprintf(debugStr,"### - LoadGLTexture() - loading: %s\n",
TextureFileName);
? ? ? ?XPLMDebugString(debugStr);

? ? ? ?SDL_Surface *image; // This surface will tell us the details of
the image

? ? ? ?image = IMG_Load(TextureFileName);

? ? ? ?if (image) {
//the XPLM functions are equivalent to OpenGL
? ? ? ? ? ? ? ?XPLMGenerateTextureNumbers(&gTexture[TextureId], 1);
? ? ? ? ? ? ? ?XPLMBindTexture2d(gTexture[TextureId], 0);
? ? ? ? ? ?gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h,
GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

? ? ? ? ? ? ? ?Stat = TRUE;

? ? ? ?} else {
? ? ? ? ? ? ? ?XPLMDebugString("### LoadGLTexture(): Error loading
texture!\n");
? ? ? ? ? ? ? ?Stat = FALSE;
? ? ? ?}
if ( image ) {
? ? ? ?SDL_FreeSurface( image );
}
? ? ? ?return Stat;
}

/// Draws the textures that make up the gauge
int DrawGLScene(float x1, float y1)
{
? ? ? ?glPushMatrix();
? ? ? ?XPLMBindTexture2d(gTexture[PANEL_TEXTURE], 0);
? ? ? ?glBegin(GL_QUADS);
? ? ? ?glTexCoord2f(1, 0.0f); glVertex2f(PanelRight, PanelBottom);
// Bottom Right
Of The Texture and Quad
? ? ? ?glTexCoord2f(0, 0.0f); glVertex2f(PanelLeft, PanelBottom);
// Bottom Left
Of The Texture and Quad
? ? ? ?glTexCoord2f(0, 1.0f); glVertex2f(PanelLeft, PanelTop); // Top
Left Of The
Texture and Quad
? ? ? ?glTexCoord2f(1, 1.0f); glVertex2f(PanelRight, PanelTop);
// Top Right Of The
Texture and Quad
? ? ? ?glEnd();

? ?glPopMatrix();


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Whenever I do textures, I check to see how many bytes per pixel. I
think PNG has 4 (RGBA), but your code is using only RGB. Consider
something like:

void Texture::buildTexture(SDL_Surface * texture)
{
if (SDL_MUSTLOCK(texture)) SDL_LockSurface(texture);
glGenTextures(1, &_id);
glBindTexture(GL_TEXTURE_2D, _id);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

GL_LINEAR_MIPMAP_LINEAR);

 _width  = texture->w;
 _height = texture->h;

 if (texture->format->BytesPerPixel == 4) {
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, _width, _height, GL_RGBA,

GL_UNSIGNED_BYTE, texture->pixels);
}
else {
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, _width, _height,
GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);
}
if (SDL_MUSTLOCK(texture)) SDL_UnlockSurface(texture);
SDL_FreeSurface(texture);
}

JohnOn Wed, Jul 15, 2009 at 7:28 AM, Jonathan Dearborn wrote:

Are you flushing/swapping the buffers?

Jonny D

On Wed, Jul 15, 2009 at 6:32 AM, Hieu Le Trung wrote:

Try this
SDL_Surface *tmp; // This surface will tell us the details of the image
tmp = IMG_Load(TextureFileName);
SDL_Surface *img = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);

-----Original Message-----
From: sdl-bounces at lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org]
On Behalf Of Michael
Sent: Wednesday, July 15, 2009 5:27 PM
To: sdl at libsdl.org
Subject: [SDL] png image SDL/OpenGL

Hi
can u find out why I cannot see the image? I’m stuck…
Many thanks
Michael

/// Texture stuff
#define MAX_TEXTURES 4
#define PANEL_FILENAME “Images/pnl.png”
#define PANEL_TEXTURE 0

int LoadGLTexture(char *pFileName, int TextureId)
{
? ? ? ?int Stat = FALSE;
? ? ? ?char TextureFileName[255];

? ? ? ?/// Need to get the actual texture path
? ? ? ?/// and append the filename to it.
? ? ? ?strcpy(TextureFileName, gPluginDataFile);
? ? ? ?strcat(TextureFileName, pFileName);

? ? ? ?sprintf(debugStr,"### - LoadGLTexture() - loading: %s\n",
TextureFileName);
? ? ? ?XPLMDebugString(debugStr);

? ? ? ?SDL_Surface *image; // This surface will tell us the details of
the image

? ? ? ?image = IMG_Load(TextureFileName);

? ? ? ?if (image) {
//the XPLM functions are equivalent to OpenGL
? ? ? ? ? ? ? ?XPLMGenerateTextureNumbers(&gTexture[TextureId], 1);
? ? ? ? ? ? ? ?XPLMBindTexture2d(gTexture[TextureId], 0);
? ? ? ? ? ?gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h,
GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

? ? ? ? ? ? ? ?Stat = TRUE;

? ? ? ?} else {
? ? ? ? ? ? ? ?XPLMDebugString("### LoadGLTexture(): Error loading
texture!\n");
? ? ? ? ? ? ? ?Stat = FALSE;
? ? ? ?}
if ( image ) {
? ? ? ?SDL_FreeSurface( image );
}
? ? ? ?return Stat;
}

/// Draws the textures that make up the gauge
int DrawGLScene(float x1, float y1)
{
? ? ? ?glPushMatrix();
? ? ? ?XPLMBindTexture2d(gTexture[PANEL_TEXTURE], 0);
? ? ? ?glBegin(GL_QUADS);
? ? ? ?glTexCoord2f(1, 0.0f); glVertex2f(PanelRight, PanelBottom);
// Bottom Right
Of The Texture and Quad
? ? ? ?glTexCoord2f(0, 0.0f); glVertex2f(PanelLeft, PanelBottom);
// Bottom Left
Of The Texture and Quad
? ? ? ?glTexCoord2f(0, 1.0f); glVertex2f(PanelLeft, PanelTop); // Top
Left Of The
Texture and Quad
? ? ? ?glTexCoord2f(1, 1.0f); glVertex2f(PanelRight, PanelTop);
// Top Right Of The
Texture and Quad
? ? ? ?glEnd();

? ?glPopMatrix();


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks got it working now but the image is upsidedown. How should i
rotate it 180’?
Thanks again
Michael

Hi,

one possible solution is to manipulate the texture matrix:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(-1.0f, 1.0f, 1.0f);
glRotatef(180.0f, 0.0f, 0.0f, 1.0f);

That should do the trick.

Regards

ChristophOn Thu, 16 Jul 2009 06:57:10 +0000 (UTC), Michael wrote:

Thanks got it working now but the image is upsidedown. How should i
rotate it 180’?
Thanks again
Michael


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723
MSN : msn at evilazrael.de Yahoo! : eazrael

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

Hi againOn Thu, 16 Jul 2009 12:34:14 +0200, Christoph Nelles <@Christoph_Nelles> wrote:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(-1.0f, 1.0f, 1.0f);
glRotatef(180.0f, 0.0f, 0.0f, 1.0f);

Or after some thoughts shorter:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(1.0f, -1.0f, 1.0f);


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723
MSN : msn at evilazrael.de Yahoo! : eazrael

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt