Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. About opengl screen shot is black

About opengl screen shot is black

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsgame-devperformance
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangningyu
    wrote on last edited by
    #1

    shot.h

    /*
    Class Name:

      CTGALoader.
    
      This class loads a tga texture into this object.
      
    shot.h
    

    */

    #ifndef CTGALOADER_H
    #define CTGALOADER_H

    // Remember to place all your GL/system header files that you will need to run class function

    class CTGALoader
    {
    public:
    CTGALoader(); // Constructor.
    ~CTGALoader(); // Destructor.

      bool LoadTGAFile(char \*filename);   // Load a .tga image file.
      void SaveTGAScreenShot(char \*filename,
                             int width,
                             int height); // Save a .tga screen shot.
      void FreeImage();                   // Delete a image.
    
      unsigned int ID;                    // ID used for generating the textures in OpenGl.
      int imageWidth;                     // Width of a texture.
      int imageHeight;                    // Height of a texture.
    

    protected:
    void GenerateTexture(); // Generate a texture in OpenGL.
    bool LoadTGA(char *filename); // Load a tga image.
    bool WriteTGA(char *file, short int width,
    short int height,
    unsigned char *image); // Write a tga file.

      unsigned char \*image;               // Texture image.
      bool textureExist;                  // This will be used if the image was loaded.
      int type;                           // Image format.
    

    };

    #endif

    shot.cpp

    /*
    Class Name:

      CTGALoader.
    
    shot.h
    

    */

    #include"shot.h"

    #include
    #include <./gl/GL.H>
    #include <./gl/GLU.H>
    #include

    #pragma comment(lib,"OPENGL32.LIB")
    #pragma comment(lib,"Glu32.lib")

    CTGALoader::CTGALoader()
    {
    // Give everything default values.
    image = 0;
    textureExist = false;
    type = 0;
    }

    CTGALoader::~CTGALoader()
    {
    FreeImage(); // Delete all images and dynamic memory.
    }

    bool CTGALoader::LoadTGAFile(char *file)
    {
    if(textureExist)
    FreeImage();

    if(!LoadTGA(file))
    return false;

    // Make sure the image loaded.
    if(image == 0)
    {
    return false;
    }

    GenerateTexture();

    textureExist = true;

    return true;
    }

    void CTGALoader::GenerateTexture()
    {
    // Generate the texture and text the id to the images id.
    glGenTextures(1, &ID);

    // Here we bind the texture and set up the filtering.
    glBindTexture(GL_TEXTURE_2D, ID);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    L S 2 Replies Last reply
    0
    • W wangningyu

      shot.h

      /*
      Class Name:

        CTGALoader.
      
        This class loads a tga texture into this object.
        
      shot.h
      

      */

      #ifndef CTGALOADER_H
      #define CTGALOADER_H

      // Remember to place all your GL/system header files that you will need to run class function

      class CTGALoader
      {
      public:
      CTGALoader(); // Constructor.
      ~CTGALoader(); // Destructor.

        bool LoadTGAFile(char \*filename);   // Load a .tga image file.
        void SaveTGAScreenShot(char \*filename,
                               int width,
                               int height); // Save a .tga screen shot.
        void FreeImage();                   // Delete a image.
      
        unsigned int ID;                    // ID used for generating the textures in OpenGl.
        int imageWidth;                     // Width of a texture.
        int imageHeight;                    // Height of a texture.
      

      protected:
      void GenerateTexture(); // Generate a texture in OpenGL.
      bool LoadTGA(char *filename); // Load a tga image.
      bool WriteTGA(char *file, short int width,
      short int height,
      unsigned char *image); // Write a tga file.

        unsigned char \*image;               // Texture image.
        bool textureExist;                  // This will be used if the image was loaded.
        int type;                           // Image format.
      

      };

      #endif

      shot.cpp

      /*
      Class Name:

        CTGALoader.
      
      shot.h
      

      */

      #include"shot.h"

      #include
      #include <./gl/GL.H>
      #include <./gl/GLU.H>
      #include

      #pragma comment(lib,"OPENGL32.LIB")
      #pragma comment(lib,"Glu32.lib")

      CTGALoader::CTGALoader()
      {
      // Give everything default values.
      image = 0;
      textureExist = false;
      type = 0;
      }

      CTGALoader::~CTGALoader()
      {
      FreeImage(); // Delete all images and dynamic memory.
      }

      bool CTGALoader::LoadTGAFile(char *file)
      {
      if(textureExist)
      FreeImage();

      if(!LoadTGA(file))
      return false;

      // Make sure the image loaded.
      if(image == 0)
      {
      return false;
      }

      GenerateTexture();

      textureExist = true;

      return true;
      }

      void CTGALoader::GenerateTexture()
      {
      // Generate the texture and text the id to the images id.
      glGenTextures(1, &ID);

      // Here we bind the texture and set up the filtering.
      glBindTexture(GL_TEXTURE_2D, ID);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Far too much code here and far too few details. Try and narrow the problem down to a specific area of code and explain what is not working.

      speaking as ...

      1 Reply Last reply
      0
      • W wangningyu

        shot.h

        /*
        Class Name:

          CTGALoader.
        
          This class loads a tga texture into this object.
          
        shot.h
        

        */

        #ifndef CTGALOADER_H
        #define CTGALOADER_H

        // Remember to place all your GL/system header files that you will need to run class function

        class CTGALoader
        {
        public:
        CTGALoader(); // Constructor.
        ~CTGALoader(); // Destructor.

          bool LoadTGAFile(char \*filename);   // Load a .tga image file.
          void SaveTGAScreenShot(char \*filename,
                                 int width,
                                 int height); // Save a .tga screen shot.
          void FreeImage();                   // Delete a image.
        
          unsigned int ID;                    // ID used for generating the textures in OpenGl.
          int imageWidth;                     // Width of a texture.
          int imageHeight;                    // Height of a texture.
        

        protected:
        void GenerateTexture(); // Generate a texture in OpenGL.
        bool LoadTGA(char *filename); // Load a tga image.
        bool WriteTGA(char *file, short int width,
        short int height,
        unsigned char *image); // Write a tga file.

          unsigned char \*image;               // Texture image.
          bool textureExist;                  // This will be used if the image was loaded.
          int type;                           // Image format.
        

        };

        #endif

        shot.cpp

        /*
        Class Name:

          CTGALoader.
        
        shot.h
        

        */

        #include"shot.h"

        #include
        #include <./gl/GL.H>
        #include <./gl/GLU.H>
        #include

        #pragma comment(lib,"OPENGL32.LIB")
        #pragma comment(lib,"Glu32.lib")

        CTGALoader::CTGALoader()
        {
        // Give everything default values.
        image = 0;
        textureExist = false;
        type = 0;
        }

        CTGALoader::~CTGALoader()
        {
        FreeImage(); // Delete all images and dynamic memory.
        }

        bool CTGALoader::LoadTGAFile(char *file)
        {
        if(textureExist)
        FreeImage();

        if(!LoadTGA(file))
        return false;

        // Make sure the image loaded.
        if(image == 0)
        {
        return false;
        }

        GenerateTexture();

        textureExist = true;

        return true;
        }

        void CTGALoader::GenerateTexture()
        {
        // Generate the texture and text the id to the images id.
        glGenTextures(1, &ID);

        // Here we bind the texture and set up the filtering.
        glBindTexture(GL_TEXTURE_2D, ID);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        S Offline
        S Offline
        Software_Developer
        wrote on last edited by
        #3

        You have to draw some graphics first.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups