This code displays a white texture always except when the dimensions are 383 x 512
img.size.height = 512;
img.size.width = 383;
img.data = new uint8_t[img.size.width * img.size.height*3];
memset(img.data, 'a', img.size.width * img.size.height*3);
if (!glfwInit())
{
error("Failed to initialize glfw\n");
}
GLFWwindow* window = glfwCreateWindow(983, 720, "Hello", NULL, NULL);
screenRatio = 983.0 / 720.0;
textureRatio = (float)img.size.width / (float)img.size.height;
calculate_quad_dimensions();
if (!window)
error("Failed to create GLFWwindow");
glfwMakeContextCurrent(window);
int err = glewInit();
if (err != GLEW_OK)
{
error("Failed to initialize GLEW.");
}
GLCall(glClearColor(0.20, 0.20, 0.20, 1));
glEnable(GL_TEXTURE_2D);
glfwSetWindowSizeCallback(window, size_callback);
glfwSetKeyCallback(window, key_callback);
glfwSwapInterval(1);
GLuint texture;
GLCall(glGenTextures(1, &texture));
GLCall(glBindTexture(GL_TEXTURE_2D, texture));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, img.size.width, img.size.height, 0, GL_RGB, GL_UNSIGNED_BYTE, img.data));
glGenerateMipmap(GL_TEXTURE_2D);
delete[] img.data;
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(offsetx + 0.0, offsety + 0.0); glVertex2f(-quadWidth, -quadHeight); // Lower left
glTexCoord2f(offsetx + 1, offsety + 0.0); glVertex2f(quadWidth, -quadHeight); // Lower right
glTexCoord2f(offsetx + 1, offsety + 1); glVertex2f(quadWidth, quadHeight); // Upper right
glTexCoord2f(offsetx + 0.0, offsety + 1); glVertex2f(-quadWidth, quadHeight); // upper left
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
when the dimensions are 383 x 512, the image has glitched random pixels at the top row:
any other dimension i tried, the image is pure white. This is a problem because im making a photo viewer app and the thumbnail is the dimension 383 x 512, and the garbage pixels at the top row are pushing the image down skewing it.