Results 1 to 9 of 9

Thread: Sequence of RGBA channels in DDS

  1. #1
    Join Date
    Jul 2012
    Location
    Moscow
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Sequence of RGBA channels in DDS

    Hello.
    There is a method to change a sequence of RGBA channels directly in DDS files of textures?
    The problem is that (if I am not mistaken) means of Qt allow to read only DDS files, but not to change them.
    I couldn't find the solution of this problem. ((
    p.s. Unfortunately with DDS I have no experience.
    Thanks in advance.
    Last edited by maxoutlaw; 11th September 2012 at 16:38. Reason: spelling corrections
    War... war never changes...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sequence of RGBA channels in DDS

    You can use pure OpenGL calls to load the texture.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Location
    Moscow
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sequence of RGBA channels in DDS

    Quote Originally Posted by wysota View Post
    You can use pure OpenGL calls to load the texture.
    You can show me a simple example of opening and saving of textures please?
    I have no experience in this area, and I don't know, with what I need to begin.
    War... war never changes...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sequence of RGBA channels in DDS

    I think it will be easier if you ask at some OpenGL forum
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2012
    Location
    Moscow
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sequence of RGBA channels in DDS

    I found a method:
    1) texture loading by means of QtOpenGL;
    2) receiving QImage from QGLPixelBuffer;
    3) change of an order of channels;
    4) image writing in the file means of API for Nvidia Texture Tools 2.

    But I had a problem on 1 step - I am not sure that correctly I load a texture because the received image contains only black color aka Malevich's Black Square.

    ddstexture.h
    Qt Code:
    1. #ifndef DDSTEXTURE_H
    2. #define DDSTEXTURE_H
    3.  
    4. #include <QtOpenGL>
    5. #include <QGLWidget>
    6. #include <QImage>
    7. #include <QDebug>
    8. #include <nvtt/include/nvtt.h>
    9.  
    10. class DDSTexture : public QGLWidget
    11. {
    12. Q_OBJECT
    13.  
    14. private:
    15. struct DDS_PIXELFORMAT{
    16. unsigned long Size;
    17. unsigned long Flags;
    18. unsigned long FourCC;
    19. unsigned long RGBBitCount;
    20. unsigned long RBitMask;
    21. unsigned long GBitMask;
    22. unsigned long BBitMask;
    23. unsigned long ABitMask;
    24. };
    25.  
    26. typedef struct{
    27. unsigned long Size;
    28. unsigned long Flags;
    29. unsigned long Height;
    30. unsigned long Width;
    31. unsigned long PitchOrLinearSize;
    32. unsigned long Depth;
    33. unsigned long MipMapCount;
    34. unsigned long Reserved1[11];
    35. DDS_PIXELFORMAT ddspf;
    36. unsigned long Caps;
    37. unsigned long Caps2;
    38. unsigned long Caps3;
    39. unsigned long Caps4;
    40. unsigned long Reserved2;
    41. }DDS_HEADER;
    42.  
    43. QSize p_getDDSSize(const QString &path);
    44. QImage p_getImageFromDDS(const QString &path);
    45.  
    46. QImage image;
    47. QGLPixelBuffer *pbuffer;
    48.  
    49. public:
    50. explicit DDSTexture(QWidget *parent = 0);
    51. ~DDSTexture();
    52.  
    53. signals:
    54.  
    55. public slots:
    56.  
    57. };
    58.  
    59. #endif // DDSTEXTURE_H
    To copy to clipboard, switch view to plain text mode 

    ddstexture.cpp
    Qt Code:
    1. #include "ddstexture.h"
    2.  
    3. QSize DDSTexture::p_getDDSSize(const QString &path)
    4. {
    5. DDS_HEADER DDSHeader = {0};
    6. DDSHeader.Size = sizeof(DDS_HEADER);
    7. QFile ddsFile(path);
    8. if(ddsFile.open(QIODevice::ReadOnly)){
    9. ddsFile.seek(4);
    10. ddsFile.read((char*)&DDSHeader, sizeof(DDS_HEADER));
    11. }
    12. ddsFile.close();
    13. qDebug() << "height = " << DDSHeader.Height;
    14. qDebug() << "width = " << DDSHeader.Width;
    15. qDebug() << "size = " << DDSHeader.Size;
    16.  
    17. return QSize(DDSHeader.Width, DDSHeader.Height);
    18. }
    19.  
    20. QImage DDSTexture::p_getImageFromDDS(const QString &path)
    21. {
    22. pbuffer = new QGLPixelBuffer(p_getDDSSize(path), format(), this);
    23. makeCurrent();
    24. pbuffer->bindTexture(path);
    25. QImage image = pbuffer->toImage();
    26. image.save("D:\\Programming\\MyProjects\\ConverterChannelsDDS\\test.png", "PNG");
    27. return pbuffer->toImage();
    28. }
    29.  
    30.  
    31.  
    32. DDSTexture::DDSTexture(QWidget *parent):QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
    33. {
    34. this->p_getImageFromDDS(QString("D:\\Programming\\MyProjects\\ConverterChannelsDDS\\wind_01_n.dds"));
    35. }
    36.  
    37. DDSTexture::~DDSTexture()
    38. {
    39. delete pbuffer;
    40. }
    To copy to clipboard, switch view to plain text mode 

    What do I do not correctly?
    p.s. I need to process channels only, without an output of the loaded texture somewhere.
    War... war never changes...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sequence of RGBA channels in DDS

    You don't need QGLWidget then. QGLContext should be enough.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2012
    Location
    Moscow
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sequence of RGBA channels in DDS

    Quote Originally Posted by wysota View Post
    QGLContext should be enough.
    I tried to use QGLContext, but it isn't created - doesn't pass check on a validity:
    Qt Code:
    1. DDSChannels::DDSChannels(QObject *parent):QObject(parent)
    2. {
    3. pixmap = new QPixmap;
    4. glContext = new QGLContext(QGLFormat::defaultFormat(), pixmap);
    5. glContext->makeCurrent();
    6. qDebug() << "GLContext is valid: " << glContext->isValid();
    7. qDebug() << "texture ID is: " << glContext->bindTexture(QString("D:\\Programming\\MyProjects\\ConverterChannelsDDS\\wind_01_n.dds"));
    8. }
    To copy to clipboard, switch view to plain text mode 
    GLContext is valid: false
    War... war never changes...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sequence of RGBA channels in DDS

    You didn't call QGLContext::create().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2012
    Location
    Moscow
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sequence of RGBA channels in DDS

    Quote Originally Posted by wysota View Post
    You didn't call QGLContext::create().
    I corrected a mistake,
    Qt Code:
    1. DDSChannels::DDSChannels(QObject *parent):QObject(parent)
    2. {
    3. pixmap = new QPixmap(512, 512);
    4. glContext = new QGLContext(QGLFormat::defaultFormat(), pixmap);
    5. glContext->create();
    6. glContext->makeCurrent();
    7. if(glContext->isValid()){
    8. id = glContext->bindTexture(QString("D:\\Programming\\MyProjects\\ConverterChannelsDDS\\wind_01_n.dds"));
    9. qDebug() << "texture id: " << id;
    10. qDebug() << "pixmap width: " << pixmap->width();
    11. qDebug() << "pixmap height: " << pixmap->height();
    12. qDebug() << "pixmap has alpha channel: " << pixmap->hasAlphaChannel();
    13. pixmap->save("D:\\Programming\\MyProjects\\ConverterChannelsDDS\\test.png", "PNG");
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    but when loading a texture the message is deduced:
    QGLContext::bindTexture(): The GL implementation does not support texture compression extensions.
    texture id: 0
    pixmap width: 512
    pixmap height: 512
    pixmap has alpha channel: false
    The ID of the loaded texture is zero, and the container QPixmap is empty. The file "test.png" contains only black color.
    War... war never changes...

Similar Threads

  1. Phonon control or selection of Left or right channels or both
    By windsword in forum Qt-based Software
    Replies: 0
    Last Post: 23rd September 2010, 12:48
  2. Qt ARGB and RGBA
    By zack in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2010, 22:44
  3. Haw many channels does a QPixmap have?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2009, 17:39
  4. Playing only some channels with Phonon
    By jfrousval in forum Qt Programming
    Replies: 0
    Last Post: 10th March 2009, 14:30
  5. How to output RGB image into three seperate channels?
    By elflord in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2009, 15:54

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.