Advertisement

04.15.2008 at 09:25PM PDT, ID: 23325979
[x]
Attachment Details

OpenGL texture mapping problem

Asked by lzha022 in OpenGL Graphics & Game Programming

Tags: OpenGL

Hello experts,
I do not know much about OpenGL, but i need to fix this bug (code written by someone else).
When two canvas windows  opened at the same time, the image display does not work properly. Sometimes, the whole canvas becomes black or green or red...
I think might be related to the call glGenTextures(1, &textureID) - the main windows mixed the textureID in the two cavas windows. But the code related to this part is like this
        if(!glIsTexture(textureId))
          glGenTextures(1,&textureId);
Looks like the above code will make sure the textureID be unique, is it?
Any other idea why this problem happens?

Thanks.
AlisonStart Free Trial
[+][-]04.16.2008 at 09:55PM PDT, ID: 21374268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 09:58PM PDT, ID: 21374279

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 10:11PM PDT, ID: 21374321

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 01:33PM PDT, ID: 21381070

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 09:48PM PDT, ID: 21383374

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: OpenGL Graphics & Game Programming
Tags: OpenGL
Sign Up Now!
Solution Provided By: ikework
Participating Experts: 1
Solution Grade: B
 
 
[+][-]04.17.2008 at 09:51PM PDT, ID: 21383384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 09:58PM PDT, ID: 21383406

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:32PM PDT, ID: 21397984

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:48AM PDT, ID: 21404767

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 02:59PM PDT, ID: 21406472

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:31PM PDT, ID: 21408489

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:34PM PDT, ID: 21408506

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 01:42PM PDT, ID: 21415379

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 02:17PM PDT, ID: 21415717

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 10:58PM PDT, ID: 21418026

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 11:30PM PDT, ID: 21418146

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.23.2008 at 02:24PM PDT, ID: 21425574

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 01:47AM PDT, ID: 21444933

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 09:07PM PDT, ID: 21451550

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 01:21AM PDT, ID: 21531083

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.16.2008 at 09:55PM PDT, ID: 21374268
hey lzha022.

if you have two opengl windows, then you need two opengl-contexts. two contexts cant share the same texture-id.you have to generate one textureid for each gl-context.

ike
 
04.16.2008 at 09:58PM PDT, ID: 21374279
Hi Ikework,
Thanks for your reply. But how do i use two openGL-contextx? As both the two windows share the same canvas class.
 
04.16.2008 at 10:11PM PDT, ID: 21374321
>> As both the two windows share the same canvas class.

are you talking about Qt-canvas?
 
04.17.2008 at 01:33PM PDT, ID: 21381070
>>are you talking about Qt-canvas?

Yes, Qt canvas.
 I checked the code again, one openGL window has 4 canvases (same canvas class), another openGL window has one canvas (different cavas class). If i open the two openGL at the same time, the images will not display properly, but each window itself works fine.
thanks
Alison
 
04.17.2008 at 09:48PM PDT, ID: 21383374
ok, each of the opengl-windows has to generate its own texture ids. you might have to use QGLWidget::makeCurrent when you generate the texture-ids. have a look at:

http://stuff.mit.edu/afs/athena/software/qt-dynamic_v4.2.1/www/qglwidget.html#makeCurrent

Accepted Solution
 
04.17.2008 at 09:51PM PDT, ID: 21383384
Thanks ikework.
It is time to go home, i will have a look next Monday.
Have a good weekend!
 
04.17.2008 at 09:58PM PDT, ID: 21383406
thanks alison .. to you too :)
 
04.20.2008 at 04:32PM PDT, ID: 21397984
Hi ikework,
I made some changes to the code. I can not call makeCurrrent immediately before i generate the texture ids as the code below will show you
void  TwoDCanvas::paintGL()
{
  this->makeCurrent();
  implement->paintGL();
}/* void  TwoDCanvas::paintGL() */
The actual drawing part is in  implement->paintGL(). implement is just a normal c++ class.
The image disply looks better but still does not work correctly.
Have you got any other idea?
thanks
Alison
 
04.21.2008 at 11:48AM PDT, ID: 21404767
just create the texture-ids in the initialize function of the OpenGL-widget

>> but still does not work correctly.

can you explain what is wrong?
 
04.21.2008 at 02:59PM PDT, ID: 21406472
Hi ikework,
I have cines to display, so creating texture-ids in the initialize function will not work.

>>can you explain what is wrong?
The images do not display propery as before but a bit better - maybe because of the makeCurrent call before implement->paintGL();
 
04.21.2008 at 11:31PM PDT, ID: 21408489
what are cines? there is a virtual function QGLWidget::initializeGL()  what i mean is this:

class YourClass : public QGLWidget
{
public:
    virtual void initializeGL ();

    ....

private:
    GLuint texture_id;
};

void YourClass::initializeGL ()
{
    // load your texturefile ..
    ....
 
    // generate the texture-id
    glGenTextures( 1, &texture_id );
    glBindTexture( GL_TEXTURE_2D, texture_id );
   
    glTexImage2D( GL_TEXTURE_2D, ..

}


>> The images do not display propery as before but a bit better

can you upload the texture and a screenshot of your application?
 
04.21.2008 at 11:34PM PDT, ID: 21408506
have a look at this for more details:

http://doc.trolltech.com/4.3/qglwidget.html#details
 
04.22.2008 at 01:42PM PDT, ID: 21415379
Hi ikework,
cines are movies in our project - sorry about this. There are lots of images in one movie, so it is not possible to generate all texture_ids in initializeGL.
All the texture_ids are generated in renderCanvas() in my code.
Thanks
Alison
 
04.22.2008 at 02:17PM PDT, ID: 21415717
Hi ikework,
Here is a screenshot. The yellow images should look like the other image. but they turn yellow, sometimes some images are white or red.
 
error
error
 
 
04.22.2008 at 10:58PM PDT, ID: 21418026
can you show the code of your QGLWidget, especially initializeGL() and paintGL()
 
04.22.2008 at 11:30PM PDT, ID: 21418146
1) what is rendered in the second gl-window. the movie as well? if it has static-textures at least you can generate them in its initializeGL() functions

2) are you sure you have to use opengl to render the movie, seems to be overkill to me. better convert it to a common movie-format and use a plugin to render it
 
04.23.2008 at 02:24PM PDT, ID: 21425574
some code:

QGLWidget
void  MyCanvas::initializeGL()
{
  initialiseCoords();
  implement->initializeGL();        
}
void  MyCanvas::paintGL()
{
  this->makeCurrent();  //i added this line of code
  implement->paintGL();
}
implement is class MyCanvasImpl
void MyCanvasImpl::initializeGL()
{
  glClearColor (0.0, 0.0, 0.0, 0.0);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glEnable(GL_TEXTURE_2D);
  glShadeModel(GL_FLAT);
  // Initialize the "OpenGL Extension Wrangler" library
  glewInit();
  glEnable(GL_COLOR_TABLE);
  initialised = true;
}
void myCanvasImpl::paintGL()
{
  renderCanvas();
}
void myCanvasImpl::renderCanvas(void)
{
  if (initialised)
  {
    setCoords();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawImage();
   ...
}

image will be updated by calling setImage() from outside for showing movies
 myCanvasImpl::drawImage()
{
...
 for(int i=0;i<imageSize*imageSize;i++)
        {
          short filteredValue = (short)(contrast*(image[i] - brightness) + 127.5f);    
          if (filteredValue > 255)
          {
            filteredValue = 255;
          }
          else if (filteredValue < 0)
          {
            filteredValue = 0;
          }
          imageData[i] = (unsigned char)filteredValue;
        }
        glPixelStorei(GL_UNPACK_ALIGNMENT,1);
        if(!glIsTexture(textureId))
          glGenTextures(1,&textureId);
        glBindTexture(GL_TEXTURE_2D,textureId);
...
}
I am not quite familiar with openGl, and the code has been there for a long time. Maybe my unclear discription confused you.
Thanks
 
04.26.2008 at 01:47AM PDT, ID: 21444933
you never delete "textureid" before reusing it.

add this to initializeGL:

void MyCanvasImpl::initializeGL()
{
  glClearColor (0.0, 0.0, 0.0, 0.0);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glEnable(GL_TEXTURE_2D);
  glShadeModel(GL_FLAT);
  // Initialize the "OpenGL Extension Wrangler" library
  glewInit();
  glEnable(GL_COLOR_TABLE);
  initialised = true;
  textureId = 0;  // <<<<<<<<<<<<<<<<<<< init textureid to zero
}

and before you call glGenTextures, you must delete it, before reusing it:

myCanvasImpl::drawImage()
{
...
 for(int i=0;i<imageSize*imageSize;i++)
        {
          short filteredValue = (short)(contrast*(image[i] - brightness) + 127.5f);    
          if (filteredValue > 255)
          {
            filteredValue = 255;
          }
          else if (filteredValue < 0)
          {
            filteredValue = 0;
          }
          imageData[i] = (unsigned char)filteredValue;
        }
        glPixelStorei(GL_UNPACK_ALIGNMENT,1);
       
        // add this if-block to delete the textureid, before reusing it
        if( 0 != textureId )
        {
            glDeleteTextures( 1, &textureId )
            textureid=0;
        }
        glGenTextures(1,&textureId);
        glBindTexture(GL_TEXTURE_2D,textureId);
...
}


can you answer the 2 questions from my previous post anyway ;)
 
04.27.2008 at 09:07PM PDT, ID: 21451550
Hi ikework,
the program works the same after i changed the code as above.
>1) what is rendered in the second gl-window. the movie as well? if it has static-textures at least you >can generate them in its initializeGL() functions
Yes, the other window also display movie as well, but the code looks better as all textureIds generated in InitializeGL()
void myThreeDCanvasImpl::initializeGL()
{
  glClearColor (0.0, 0.0, 0.0, 0.0);
  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
  glGenTextures(numImages, textureId);   //GLuint                *textureId;
...
}

2) are you sure you have to use opengl to render the movie, seems to be overkill to me. better convert it to a common movie-format and use a plugin to render it.
I think so, the movie is just help users to view all images in a consecutive way, the users need to put some points on each image.
 
05.09.2008 at 01:21AM PDT, ID: 21531083
>> better convert it to a common movie-format and use a plugin to render it.
after some thinking about it i guess the problem remains the same. there are some things you have to ntake care of. each line hab to be alogned on 4 bytes.
if you dont mind ploease upload the project. i would be interest in helping you, since the matter is very interesting to me too :)

ike
 
 
20080716-EE-VQP-32 / EE_QW_2_20070628