Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Two issues: OpenGL and image saving

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Two issues: OpenGL and image saving
#4112
Posted by: 2004-05-14 05:20:24
Hi all,

I've got a nearly-completed wxWidgets/wxWindows project built here (based on 2.4.2; cross-compiling between Windows and Linux), and there's two things I just can't figure out... and Google-ing didn't help much either.

Firstly, I've got my program functioning the way I want under Windows, but under Linux (Mandrake, IDE: KDevelop3, Mesa for OpenGL), the openGL renders as a lovely black screen.  Well, that's not entirely true.  If I use a glFrustum call, all renders perfectly.  However, when I switch to a gluPerspective call, I get the black screen issue.  It's not a clipping problem or anything like that, since it renders properly under Windows.  It's also not an OpenGL or GLU issue, since I can run other non-wxWidgets programs using gluPerspective without problem.  So I'm left to believe this is a wxWidgets problem.  Has anyone heard of this -- and hopefully, heard of a solution, as well?

Secondly, I've defined an openGL canvas ( class canvas: public wxGLCanvas {...}; ) that I want to be able to capture and export to an image (jpg, bmp, whatever).  I managed to find a newsgroup posting that said I should be able to do this in about 10 lines, but I can't for the life of me figure it out.  Part of the problem could be that I'm using a wxPaintDC rather than a wxClientDC.  However, this is necessity, because switching to a wxClientDC causes issues with disappearing message/dialog boxes.  Anyways, I'm looking for some kind person to help me out with a function that will take my openGL canvas and save it as an image.

Thanks all; sorry for the long post/explanation

Maverick
Message2. Re: Two issues: OpenGL and image saving
#5262
Posted by: 2004-10-19 00:01:28
I can't help with the first question other than suggesting that you update your OpenGL drivers.

For the second question, try something like the following:

void YourGLCanvas::TakeScreenshot() {
      wxSize s = GetSize() ;
  
   // Copy from OpenGL
   wxImage image(s.GetWidth(), s.GetHeight());
   unsigned char* pPixelData = image.GetData(); // Pointer to image buffer
   glReadPixels(0, 0, s.GetWidth(), s.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE,
            pPixelData);
  
   // flip the image to the proper orientation
   image = image.Mirror(false);
        if (addedImageHandler == 0) {   
      wxInitAllImageHandlers();
           addedImageHandler = 1;
   }
   image.SaveFile("screenshot1.jpeg", wxBITMAP_TYPE_JPEG);
}

Hope this helps. . .
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-10-3  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0