我在vs2013上写了一个图形项目,但是那时我还好,但我不得不回到2010年。
现在我已经完成了在我有多个纹理渲染之前,只有一个纹理会渲染到屏幕上。
我有背景和球员。我将纹理加载到背景中:
background = new GLuint(loadPNG("images/Background/Background.png"));
playerDown = loadPNG("images/playerDown.png");
GLuint Game::loadPNG(char * name)
nv::Image img;
GLuint myTextureID;
// Return true on success
if (img.loadImageFromFile(name))
{
glGenTextures(1, &myTextureID);
glBindTexture(GL_TEXTURE_2D, myTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, img.getInternalFormat(), img.getWidth(), img.getHeight(), 0, img.getFormat(), img.getType(), img.getLevel(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
}
else
//MessageBox(NULL, "Failed to load texture", "End of the world", MB_OK | MB_ICONINFORMATION);
return myTextureID;
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, *background);
glPushMatrix();
glBegin(GL_POLYGON);
glTexCoord2f(1.0, 1.0); glVertex2f(gameWidth, gameHeight);
glTexCoord2f(0.0, 1.0); glVertex2f(0, gameHeight);
glTexCoord2f(0.0, 0.0); glVertex2f(0, 0);
glTexCoord2f(1.0, 0.0); glVertex2f(gameWidth , 0);
glEnd();
glPopMatrix();
glTranslatef(xMovement, yMovement, 0.f);
player->draw();
void Entity::draw()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glPushMatrix();
glTranslatef(m_X, m_Y, 0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 1.0); glVertex2f(m_Width, m_Height);
glTexCoord2f(1.0, 1.0); glVertex2f(0, m_Height);
glTexCoord2f(1.0, 0.0); glVertex2f(0, 0);
glTexCoord2f(0.0, 0.0); glVertex2f(m_Width, 0);
glEnd();
glPopMatrix();
}
我是C ++的新手,但我对它在vs2013中的运作方式感到困惑,但是当我改为2010年时,它现在只会在绘制时显示一个纹理