Код: < /p>
Код: Выделить всё
#include
#include
#include
int ww = 500, wh = 500;
void display()
{
glClearColor(1.0, 1.0, 0.7, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glEnable(GL_TEXTURE_2D);
glTexCoord2f(0.0, 0.0); glVertex3f(10,10,0);
glTexCoord2f(0.0, 1.0); glVertex3f(10,wh-10,0);
glTexCoord2f(1.0, 1.0); glVertex3f(ww-10,wh,0);
glTexCoord2f(1.0, 0.0); glVertex3f(ww-10,10,0);
glDisable(GL_TEXTURE_2D);
glEnd();
glFlush();
}
void myinit()
{
glViewport(0, 0, ww, wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)ww, 0.0, (GLdouble)wh);
glMatrixMode(GL_MODELVIEW);
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
int width, height, nrChannels;
unsigned char* data = stbi_load("container.jpg", &width, &height, &nrChannels, 0);
if (data)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
}
else
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/72945477/textured-quad-fails-to-render[/url]