osx - openGL texture loading -> weird looking result [mac, glfw, stb_image] -
i having trouble loading textures in opengl.
i writing cpp on mac , have hard time. don't understand why having these ugly textures. using stb_image.c load textures, doesnt seem work correctly.
here code:
unsigned int texturehelper::loadtexture(std::string pathtotexture){ std::cout << "loading " << pathtotexture << std::endl; unsigned int img; glgentextures(1,&img); glbindtexture(gl_texture_2d,img); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge); /* load texture stb_image */ int width, height, n; unsigned char * data = stbi_load(pathtotexture.c_str(), &width, &height, &n, 4); if(!data){ printf("error, while loading texture: %s\n", stbi_failure_reason()); }else{ glteximage2d(gl_texture_2d, 0, gl_rgba, width, height, 0, gl_rgba, gl_unsigned_byte, data); stbi_image_free(data); std::cout << "returning " << pathtotexture << " = " << img << "x" << width << "x" << height << "x" << n << std::endl; return img; } std::cout << "returning " << pathtotexture << " = " << 0 << std::endl; return 0;
}
i have tried gl_rgba, gl_rgba8, gl_rgb, gl_rgba..but nothing seems work. missing something?
as gl context, using glfw , apple gl3.h
format of tex .png
here come textures :)
update: solved alright guys. have solved it. sorry posting ;) "bit" embarrassing^^... code there works fine. problem was, forgot set glfw colorbits , depth...
adding this
glfwwindowhint(glfw_red_bits, 8); glfwwindowhint(glfw_green_bits, 8); glfwwindowhint(glfw_blue_bits, 8); glfwwindowhint(glfw_alpha_bits, 8); glfwwindowhint(glfw_depth_bits, 32);
before window creation solved problem.
Comments
Post a Comment