openGL alpha problem

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

openGL alpha problem

Post by lerabot »

I've been trying to search around but couldn't find a proper answer to this question,

I've been using the png_to_texture and draw_textured_quad fonction from this tutorial -> http://dcemulation.org/?title=Loading_P ... L_textures and I can't seem to get any apha to work.

my "main" code looks like this,

Code: Select all

int main()
{
  //This is the GL init for the GL PNG exemple
  glKosInit();
  glScalef(1.f/320.f, 1.f/240.f, 1.f);

  //this image has alpha
  int ret = png_to_gl_texture(&t, "/rd/face_2.png"); 
  //this image has no alpha channel
  png_to_gl_texture(&bg, "/rd/grid.png");
 
  ////////////////////////////////
  //Debug info for images
  setParam(1, "f2=");
  setInt(1, t.format);
  setParam(2, "bg=");
  setInt(2, bg.format);

  //glClearColor(0.0f, 1.0f, 0.0f, 0.0f); // Clear The Background Color To Black
  //glClearDepth(1.0);  // Enables Clearing Of The Depth Buffer
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);

  while(1)
  {
    updateCont();

    draw_textured_quad(&bg, -256, 0);
    draw_textured_quad(&t, tPos[0], tPos[1]);

    glutSwapBuffers();
    debugScreen();
  }
  return(0);
}



I can get all my image to show up if glEnable(GL_BLEND) is commented out.
if it's active, I can only get the bg (no alpha channel) image to show up, the one with alpha is completely invisible

any inputs?
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: openGL alpha problem

Post by dcTom »

100 % sure the gfx files are ok? especially the one with the alpha.

if you want you can sent me the 2 files an i test them with my engine.

also if you want you can sent me the complete code in a zip file and i can make some test.

for the first view the code looks ok.

but im not so good in theoretic stuff,
im better in testing
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: openGL alpha problem

Post by dcTom »

so i checked the code


just to make sure we talk about the same thing

the background ist this "blue" grid. and there is a pink "head" object

and there is a courser (glass with no alpha) that i can move with the D-Pad

Code: Select all

int ret = png_to_gl_texture(&t, "/rd/face_2.png");
  //int ret2 = png_to_gl_texture(&t2, "/rd/12dbsoft.png");
  png_to_gl_texture(&bg, "/rd/grid.png");
  png_to_gl_texture(&cursor, "/rd/cursor.png");

not sure what this is doing. you wrote debug stuff, so i havent checkt it

Code: Select all

setParam(1, "f2=");
  setInt(1, t.format);
  setParam(2, "bg=");
  setInt(2, bg.format);
i used this line //draw_textured_zquad(&t2, tPos[0], tPos[1], 2); changed &t2 -> &t
deleted draw_textured_quad(&cursor, tPos[0], tPos[1]);

Code: Select all

draw_textured_quad(&bg, -256, 0);
    draw_textured_quad(&bg, 256, 0);
    draw_textured_quad(&cursor, tPos[0], tPos[1]);
    //drawSquare(200,200, 25, 0, 1, 0);
    //draw_textured_zquad(&t2, tPos[0], tPos[1], 2);
    //draw_textured_zquad(&bg, 0, 0, 0);

now i have the background with the pink head also with blend, and its working fine.
so your code is working, perhaps you loaded the texture into t but used t2 and
lined-out the png_to_gl of t2???


so this is the code i used and it works. i test it on a real HW not EMU

Code: Select all

int ret = png_to_gl_texture(&t, "/rd/face_2.png");
  //int ret2 = png_to_gl_texture(&t2, "/rd/12dbsoft.png");
  png_to_gl_texture(&bg, "/rd/grid.png");
  png_to_gl_texture(&cursor, "/rd/cursor2.png");
  setParam(1, "f2=");
  setInt(1, t.format);
  setParam(2, "bg=");
  setInt(2, bg.format);

  /////
  //scene fiole
  //loadScene();

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Clear The Background Color To Black
  glClearDepth(1.0);  // Enables Clearing Of The Depth Buffer
  //glDisable(GL_DEPTH_TEST);
  //glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);


  while(1)
  {
    updateCont();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //drawScene();

    draw_textured_quad(&bg, -256, 0);
    draw_textured_quad(&bg, 256, 0);
    //draw_textured_quad(&t, tPos[0], tPos[1]);
    //drawSquare(200,200, 25, 0, 1, 0);
    draw_textured_zquad(&t, tPos[0], tPos[1], 2);
    //draw_textured_zquad(&bg, 0, 0, 0);
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: openGL alpha problem

Post by lerabot »

Wow... you're actually right.
Just tested it on console and it works perfectly...

Ok well sorry for that.

LESSON LEARNED : TEST ON REAL HARDWARE ;)
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: openGL alpha problem

Post by bogglez »

Author of the tutorial here, sorry I only saw the thread just now.
So everything's fine with the tutorial code?
What emulator did you use which failed to show things correctly?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: openGL alpha problem

Post by lerabot »

lxdream couldn't handle the transparency.
code is fine :)
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: openGL alpha problem

Post by lerabot »

I didn't want to start another topic for something along the same line.

Still using -lgl. When I scale a texture over another one, I get those wierd clipping effect
https://streamable.com/wa1jv

I'm litterally just changing the plane size. No different ordering or anything.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: openGL alpha problem

Post by bogglez »

Can you post code?
Do the two planes have exactly the same Z coordinate? How do you scale them, glScalef(a, a, a) instead of glScalef(a, a, 1) ?
What's your depth mode? Maybe GL_LESS instead of GL_LEQUAL might help?
Are they both drawn from the same PVR polygon batch type or is one translucent and the other isn't (not sure whether this causes problems with drawing order)?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Post Reply