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. how to use this code ??

how to use this code ??

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancetutorialquestion
10 Posts 4 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.
  • A Offline
    A Offline
    a04 lqd
    wrote on last edited by
    #1

    i have this code to load a bmp picture. but i don't know how to use it.!!! #include "stdafx.h" #include "glaux.h" #include "glut.h" GLuint texture[6]; int LoadGLTextures() { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("apple.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(3, &texture[0]); // Create Three Textures // Create Nearest Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE,TextureImage[0]->data); // ( NEW ) if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } } return Status; } //----------------------------------------------------------------------------- AUX_RGBImageRec

    L 1 Reply Last reply
    0
    • A a04 lqd

      i have this code to load a bmp picture. but i don't know how to use it.!!! #include "stdafx.h" #include "glaux.h" #include "glut.h" GLuint texture[6]; int LoadGLTextures() { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("apple.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(3, &texture[0]); // Create Three Textures // Create Nearest Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE,TextureImage[0]->data); // ( NEW ) if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } } return Status; } //----------------------------------------------------------------------------- AUX_RGBImageRec

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      What you need to do is to get an idea on what to do to use an image as texture with OpenGL by reading the code you posted. Then you can incorporate that into your project. The basic idea is not that complicated. If the piece of code you provided is part of a sample project, you can compile and run the project to see how it works. Hope this helps. Happy programming!

      A 1 Reply Last reply
      0
      • L loyal ginger

        What you need to do is to get an idea on what to do to use an image as texture with OpenGL by reading the code you posted. Then you can incorporate that into your project. The basic idea is not that complicated. If the piece of code you provided is part of a sample project, you can compile and run the project to see how it works. Hope this helps. Happy programming!

        A Offline
        A Offline
        a04 lqd
        wrote on last edited by
        #3

        Can you write a simple code which use this code as an example? thank very much. :)

        R 1 Reply Last reply
        0
        • A a04 lqd

          Can you write a simple code which use this code as an example? thank very much. :)

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          I think the code you've provided is already an example and "simple" enough (saw the inline comments?)

          “Follow your bliss.” – Joseph Campbell

          A 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            I think the code you've provided is already an example and "simple" enough (saw the inline comments?)

            “Follow your bliss.” – Joseph Campbell

            A Offline
            A Offline
            a04 lqd
            wrote on last edited by
            #5

            but i put apple.bmp in the same folder with main code, write int main() to use it. then it did not work.

            int main(int argc, char* argv[])
            {

            glutInit(&argc, argv);
            glutInitDisplayMode(GLUT\_DOUBLE | GLUT\_RGB); 
            glutInitWindowSize(640, 480); 
            glutInitWindowPosition(0, 0); 
            glutCreateWindow("Hello OpenGL!");
            OnInit(); 
            glutDisplayFunc(OnDraw); 
            glutReshapeFunc(OnSize);
            glutIdleFunc(OnIdle);
            glutKeyboardFunc(OnKey);
            //---------------------------
            glutMouseFunc(OnMouse);
            glutSpecialFunc(OnKeySpecial);
            
                LoadGLTextures();
            
            //---------------------------
            glutMainLoop();
            return 0;
            

            }

            T 1 Reply Last reply
            0
            • A a04 lqd

              but i put apple.bmp in the same folder with main code, write int main() to use it. then it did not work.

              int main(int argc, char* argv[])
              {

              glutInit(&argc, argv);
              glutInitDisplayMode(GLUT\_DOUBLE | GLUT\_RGB); 
              glutInitWindowSize(640, 480); 
              glutInitWindowPosition(0, 0); 
              glutCreateWindow("Hello OpenGL!");
              OnInit(); 
              glutDisplayFunc(OnDraw); 
              glutReshapeFunc(OnSize);
              glutIdleFunc(OnIdle);
              glutKeyboardFunc(OnKey);
              //---------------------------
              glutMouseFunc(OnMouse);
              glutSpecialFunc(OnKeySpecial);
              
                  LoadGLTextures();
              
              //---------------------------
              glutMainLoop();
              return 0;
              

              }

              T Offline
              T Offline
              Tim Craig
              wrote on last edited by
              #6

              Did you debug it to see if it could not find the file or bitmap failed to load? If you're using Visual Studio, I think you need to put the bitmap in the folder with the executable, not the source so Release or Debug.

              You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

              A 1 Reply Last reply
              0
              • T Tim Craig

                Did you debug it to see if it could not find the file or bitmap failed to load? If you're using Visual Studio, I think you need to put the bitmap in the folder with the executable, not the source so Release or Debug.

                You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                A Offline
                A Offline
                a04 lqd
                wrote on last edited by
                #7

                this is my project. draw B-spline by De Boor method, and use it to take boundary of bmp picture. http://www.mediafire.com/?4m2jrmg3lyv[^]

                T 1 Reply Last reply
                0
                • A a04 lqd

                  this is my project. draw B-spline by De Boor method, and use it to take boundary of bmp picture. http://www.mediafire.com/?4m2jrmg3lyv[^]

                  T Offline
                  T Offline
                  Tim Craig
                  wrote on last edited by
                  #8

                  That's it? Where did the executable file end up?

                  You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                  A 1 Reply Last reply
                  0
                  • T Tim Craig

                    That's it? Where did the executable file end up?

                    You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                    A Offline
                    A Offline
                    a04 lqd
                    wrote on last edited by
                    #9

                    the problem is: i have this code to load bmp picture, but i don't know how to use.

                    int LoadGLTextures();

                    i only need to load bmp picture.

                    T 1 Reply Last reply
                    0
                    • A a04 lqd

                      the problem is: i have this code to load bmp picture, but i don't know how to use.

                      int LoadGLTextures();

                      i only need to load bmp picture.

                      T Offline
                      T Offline
                      Tim Craig
                      wrote on last edited by
                      #10

                      Do you still have the box your computer came in? :doh:

                      You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                      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