Results 1 to 4 of 4

Thread: Multiple texture problem with PFD_DRAW_TO_BITMAP?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Multiple texture problem with PFD_DRAW_TO_BITMAP?

    I implemented the off-screen rendering with the PIXELFORMATDESCRIPTOR set to PFD_DRAW_TO_BITMAP instead of PFD_DRAW_TO_WINDOW. I try to render two different textures and it works fine within the PFD_DRAW_TO_WINDOW (render to screen) mode but when I try to output it to a bitmap with off-screen rendering with PFD_DRAW_TO_BITMAP mode, both of the polygon were render with the same texture (only the last initialize texture is used, the previous initialize textures are always ignore by the system). Every time when I start off-screen rendering, I will re-create all the texture list by calling Gl.glGenTexture(1000,texture); The snippet code for rendering the polygon is as follow.

    internal virtual void DrawTextureEx(int texID,VertexC vertex,PointDList cor,float []color){
    Gl.glEnable(Gl.GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
    Gl.glBindTexture(Gl.GL_TEXTURE_2D, texID);
    Gl.glBegin(Gl.GL_POLYGON);
    for(int i=0;i<vertex.Count;i++)
    {
    Gl.glTexCoord2d(cor[i].X,cor[i].Y);
    Gl.glVertex3d(vertex[i].X,vertex[i].Y,vertex[i].Z);
    }
    Gl.glEnd();
    }
    SetOpenGLState(){
    SetIniTexture();
    string fileName="";
    bool temStatus = false;

    fileName = Application.StartupPath + @"\Data\brick.bmp";
    TextureBrickWallID = LoadTextures(fileName, ref temStatus);

    fileName = Application.StartupPath + @"\Data\roof covering20.BMP";
    TextureRoof = LoadTextures(fileName, ref temStatus);
    }

    internal virtual void SetIniTexture()
    {
    Gl.glDeleteTextures(1000,texture);
    textureCounter=0;
    Gl.glGenTextures(1000,texture); // Create The Texture }


    public virtual int LoadTextures(string str,ref bool success)
    {
    int tmp = texture[textureCounter];
    success=LoadTexture(str,textureCounter,0);
    if(success==false)
    return -1;
    TextureTable[textureCounter++]=str;

    return tmp;
    }

    public virtual bool LoadTexture(string fileName,int texCount,int type)
    {
    bool status = false; // Status Indicator
    if(type==0)
    { // bitmap
    Bitmap[] textureImage = new Bitmap[1]; // Create Storage Space For The Texture
    textureImage[0] = LoadBMP(fileName); // Load The Bitmap
    // Check For Errors, If Bitmap's Not Found, Quit

    if(textureImage[0] != null)
    {
    status = true; // Set The Status To True
    textureImage[0].RotateFlip(RotateFlipType.RotateNoneFlipY); // Flip The Bitmap Along The Y-Axis
    // Rectangle For Locking The Bitmap In Memory
    Rectangle rectangle = new Rectangle(0, 0, textureImage[0].Width, textureImage[0].Height);
    // Get The Bitmap's Pixel Data From The Locked Bitmap
    BitmapData bitmapData = textureImage[0].LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

    // Typical Texture Generation Using Data From The Bitmap
    Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[texCount]);
    Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGB8, textureImage[0].Width, textureImage[0].Height, Gl.GL_BGR, Gl.GL_UNSIGNED_BYTE, bitmapData.Scan0);
    Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
    Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
    // Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_NEAREST);
    // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_OBJECT_LINEAR);
    // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_OBJECT_LINEAR);

    Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);

    // Gl.glEnable(Gl.GL_TEXTURE_GEN_S);
    // Gl.glEnable(Gl.GL_TEXTURE_GEN_T);

    if(textureImage[0] != null)
    { // If Texture Exists
    textureImage[0].UnlockBits(bitmapData); // Unlock The Pixel Data From Memory
    textureImage[0].Dispose(); // Dispose The Bitmap
    }
    Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
    Gl.glDisable(Gl.GL_TEXTURE_2D);
    }
    }
    return status; // Return The Status
    }
    Any special setting to render more than one texture under the PFD_DRAW_TO_BITMAP mode?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Multiple texture problem with PFD_DRAW_TO_BITMAP?

    PFD_DRAW_TO_BITMAP : did you check your GL version on this mode ? It should give you software renering GL 1.1 only.

    You should better use FBO (framebuffer_object) for real offscreen rendering. Searching these forums will return you tutorials and docs.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Re: Multiple texture problem with PFD_DRAW_TO_BITMAP?

    Hi, I try to use FBO for offset rendering and retrieve the texure with glGetTexImage and it is working fine for the image size less than 2048, but if try with larger image size like 4096, the glGetTexImage return empty image, the message return by glGetError() says it is an unknown error. Is it any image size limitation on FBO or glGetTexIamge? Thanks in advance!

  4. #4
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Multiple texture problem with PFD_DRAW_TO_BITMAP?

    probably yes. check the renderer capabilities before doing anything. see all glGetIntegerv values in the help as well as the additional tokens on FBO.

Similar Threads

  1. Problem with texture binding while drawing multiple objects
    By ctownboy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-04-2013, 01:06 AM
  2. PFD_DRAW_TO_BITMAP Texture
    By BingoWingo in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-19-2004, 06:57 AM
  3. PFD_DRAW_TO_BITMAP
    By ramana in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-16-2003, 12:59 AM
  4. Multiple Sub-window Buffer-to-Texture problem
    By ffunked in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-18-2003, 07:37 AM
  5. PFD_DRAW_TO_BITMAP
    By skippyj777 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-15-2000, 01:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean