【问题标题】:Set a image(jpeg | png) backgound using GLX ( opengl and Xlib)使用 GLX(opengl 和 Xlib)设置图像(jpeg | png)背景
【发布时间】:2011-06-22 02:27:16
【问题描述】:

我创建了一个带有 opengl 功能的 x11 窗口,我需要在其背景上加载一个图像(jpeg | png),其中窗口的大小大于图像,没关系。我上网获得了像使用 DevIL 或免费图像这样的资源。我不知道该使用哪一个。我使用a link to sample code 中给出的示例代码设置了 opengl 窗口,我想在 void renderGL() 中编写代码,以便将图像作为背景。如果可能的话,你能告诉我使用哪个图像库并提供代码吗?

还有在opengl中绘制彩色像素要做什么。我需要一个在窗口中绘制像素的函数,为此我必须单独提供 x,y 像素位置和 rgb 颜色(无符号整数).....

【问题讨论】:

    标签: c++ opengl x11 xlib glx


    【解决方案1】:

    我不是一个 opengl 程序员,但不知何故我做到了 及其工作

    
     ilInit(); /* Initialization of DevIL */
    ilGenImages(1, &texid); /* Generation of one image name */
    ilBindImage(texid); /* Binding of image name */
    success = ilLoadImage(backgroundimage); /* Loading of image "image.jpg" */
    iWidth = ilGetInteger(IL_IMAGE_WIDTH);
    iHeight = ilGetInteger(IL_IMAGE_HEIGHT);
    if (success){ 
    success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); // Convert every colour component into unsigned byte,replace IL_RGB with IL_RGBA  for alpha channel
    }   
    
    glGenTextures(1, &image); /* Texture name generation */
    glBindTexture(GL_TEXTURE_2D, image); /* Binding of texture name */
    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, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
    
    ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
    ilGetData()); /* Texture specification */
    
    glRotatef(roll, 0.0f,0.0f, 10.0f);     
    glOrtho(0.0, float(width), float(height), 0.0, 0.0, 100.0);
    glMatrixMode(GL_MODELVIEW);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();   // Reset The Modelview Matrix
    
    glBindTexture(GL_TEXTURE_2D, image);    // Select The First Image Texture
    glBegin(GL_QUADS);// Start Drawing A Textured Quad
    glTexCoord2i(0, 0); glVertex2f(width/2-iWidth/2,height/2-iHeight/2);
    glTexCoord2i(0, 1); glVertex2f(width/2-iWidth/2,height/2+iHeight/2);
    glTexCoord2i(1, 1); glVertex2f(width/2+iWidth/2,height/2+iHeight/2);
    glTexCoord2i(1, 0); glVertex2f(width/2+iWidth/2,height/2-iHeight/2);        
    glEnd();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2011-02-14
      相关资源
      最近更新 更多