2009-03-13 8 views
3

voici la sortie: http://i43.tinypic.com/9a5zyx.png si les choses fonctionnaient comme je le voulais, les couleurs du carré de gauche correspondraient aux couleurs du carré droit. merci pour toute aide concernant le sujetPourquoi glCopyTexSubImage2D ne copie pas correctement mon carré?

#include <gl/glfw.h> 

const char* title="test"; 
GLuint img; 
unsigned int w=64,h=64; 
int screenwidth,screenheight; 

void enable2d() 
{ 
    glMatrixMode(GL_PROJECTION); 
    glPushMatrix(); 
    glLoadIdentity(); 

    glViewport(0,0,screenwidth,screenheight); 
    glOrtho(0,screenwidth,screenheight,0,-1,1); 

    glMatrixMode(GL_MODELVIEW); 
    glPushMatrix(); 
    glLoadIdentity(); 

    glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_LIGHTING_BIT); 
    glDisable(GL_DEPTH_TEST); 
    glDisable(GL_LIGHTING); 

    glClearColor(0.0f, 0.0f, 0.0f, 0.5f); 
} 

void drawmytex() 
{ 
    glEnable(GL_TEXTURE_2D); 
    glBindTexture(GL_TEXTURE_2D,img); 
    glBegin(GL_QUADS); 
    glTexCoord2i(0,0); 
    glVertex2i(0,0); 
    glTexCoord2i(1,0); 
    glVertex2i(w,0); 
    glTexCoord2i(1,1); 
    glVertex2i(w,h); 
    glTexCoord2i(0,1); 
    glVertex2i(0,h); 
    glEnd(); 
    glDisable(GL_TEXTURE_2D); 
} 

void drawquad(int x,int y) 
{ 
    glBegin(GL_QUADS); 
    glColor3f(0.0f,1.0f,0.0f); 
    glVertex2i(x,y); 
    glColor3f(1.0f,0.0f,1.0f); 
    glVertex2i(x+w,y); 
    glColor3f(0.0f,1.0f,1.0f); 
    glVertex2i(x+w,y+h); 
    glColor3f(0.0f,0.0f,1.0f); 
    glVertex2i(x,y+h); 
    glEnd(); 
} 

void texcopy() 
{ 
    if (!glIsTexture(img)) 
     glDeleteTextures(1,&img); 
    glGenTextures(1,&img); 
    glBindTexture(GL_TEXTURE_2D,img); 
    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,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,0); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(0,w,h,0,-1,1); 
    glViewport(0,0,w,h); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
    drawquad(0,0); 

    glBindTexture(GL_TEXTURE_2D,img); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
    //glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,w,h,0); 
    glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,w,h); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(0,screenwidth,screenheight,0,-1,1); 
    glViewport(0,0,screenwidth,screenheight); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
} 

int main() 
{ 
    int running; 

    glfwInit(); 

    running=glfwOpenWindow(640,480,0,0,0,0,0,0,GLFW_WINDOW); 
    if (!running) 
    { 
     glfwTerminate(); 
     return 0; 
    } 


    glfwSetWindowTitle(title); 
    glfwEnable(GLFW_STICKY_KEYS); 
    glfwGetWindowSize(&screenwidth,&screenheight); 

    enable2d(); 
    texcopy(); 

    do 
    { 
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
     glLoadIdentity(); 

     drawquad(64,0); 
     drawmytex(); 

     glfwSwapBuffers(); 
     running=!glfwGetKey(GLFW_KEY_ESC)&&glfwGetWindowParam(GLFW_OPENED); 
     GLenum error=glGetError(); 
     if (error!=GL_NO_ERROR)running=error; 
     glfwSleep(.017); 
    } 
    while (running==1); 

    glDeleteTextures(1,&img); 

    glfwTerminate(); 
    return running; 
} 

Répondre

2

Essayez d'ajouter 'glColor3f (1,1,1);' dans votre fonction 'drawmytex'. Je soupçonne que votre texture est modulée (multipliée) avec la couleur actuelle, si c'est le cas, le problème n'est pas la copie de la texture mais la façon dont vous l'affichez.

Questions connexes