Results 1 to 3 of 3

Thread: Multitexturing with OpenGL

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Multitexturing with OpenGL

    Hi,

    I thought to try and ask here, maybe someone here is fit with OpenGL and can help.
    I am trying to do some multi texturing with OpenGL, and it "almost" works.
    I have two rectangle surfaces covered by a texture, one faces parallel to the screen, and one "tilted" 45 degrees.
    Each rectangle should be covered by another texture.
    But the result is, that only the first texture gets painted, the second not.
    Attached are two images.
    The one with one textured rectangle and the other dark brown is the result of the below posted code.
    The other, is when the GL_TEXTURE0 is used for both rectangles (instead of GL_TEXTURE1 for the second).
    It looks like GL_TEXTURE1 doesn't get initialized or something similar, but I am rather new to Open GL so I don't know what I am doing wrong.

    Thanks in advance!

    Qt Code:
    1. void gl_display(void)
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4. num_texture = 0;
    5. //init first texture
    6. glBindTexture(GL_TEXTURE_2D, g_textureNameArr[num_texture]);
    7. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture[num_texture]);
    8. gluBuild2DMipmaps(GL_TEXTURE_2D, 4, imageW, imageH, GL_RGBA, GL_UNSIGNED_BYTE, l_texture[num_texture]);
    9. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    10. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    11. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    12. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    13. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    14.  
    15. num_texture++;
    16. //init second texutre
    17. glBindTexture(GL_TEXTURE_2D, g_textureNameArr[num_texture]);
    18. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture[num_texture]);
    19. gluBuild2DMipmaps(GL_TEXTURE_2D, 4, imageW, imageH, GL_RGBA, GL_UNSIGNED_BYTE, l_texture[num_texture]);
    20. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    21. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    22. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    23. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    24. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    25. //pralell rectangle
    26. glActiveTextureARB(GL_TEXTURE0_ARB);
    27. glBindTexture(GL_TEXTURE_2D,g_textureNameArr[0]);
    28. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    29. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    30. glEnable(GL_TEXTURE_2D);
    31. //draw the textures
    32. glBegin(GL_QUADS);
    33. //map texture 0 to first rectangle
    34. glMultiTexCoord2f(GL_TEXTURE0,0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
    35. glMultiTexCoord2f(GL_TEXTURE0,0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
    36. glMultiTexCoord2f(GL_TEXTURE0,1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
    37. glMultiTexCoord2f(GL_TEXTURE0,1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
    38. //tilted rectangle
    39. glActiveTextureARB(GL_TEXTURE1_ARB);
    40. glBindTexture(GL_TEXTURE_2D,g_textureNameArr[1]);
    41. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    42. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    43. glEnable(GL_TEXTURE_2D);
    44.  
    45. glBegin(GL_QUADS);
    46. //map texture 1 to second rectangle
    47. //if in this section GL_TEXTURE0 is used, opengl2.jpg (where both rectangles get textured) is the result
    48. glMultiTexCoord2f(GL_TEXTURE1,0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
    49. glMultiTexCoord2f(GL_TEXTURE1,0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
    50. glMultiTexCoord2f(GL_TEXTURE1,1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
    51. glMultiTexCoord2f(GL_TEXTURE1,1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);
    52.  
    53. glEnd();
    54. glFlush();
    55. glDisable(GL_TEXTURE_2D);
    56. glutSwapBuffers();
    57. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by high_flyer; 31st May 2007 at 11:46.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multitexturing with OpenGL

    Hi,

    Try this link :- http://tfpsly.free.fr/english/index....texturing.html

    Hope it helps, wish I could help more but I'm more DirectX

    Regards,
    Steve

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multitexturing with OpenGL

    Thanks - but I alreday solved my problem.
    I didn post it, becaouse my problem was not multitexturing :-)
    I thought I needed mutitexturing, because I wanted to access several textures in a shader.
    But when you work with a shader, you can draw signle texture, and do the "multi texturing" in the shader it self.
    So my problem was how to pass several textures to the shader..., which is a different problem to what I have posted...

    The hard thing is to know which questions to ask!!

    Thanks though!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  2. Replies: 0
    Last Post: 4th May 2007, 10:44
  3. OpenGL ES, Qt/11 - Qtopia Core?
    By zelko in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 10:56
  4. opengl help!!
    By rachana in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2007, 08:52
  5. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.