提示コードの//コメント部内部でopencvの関数を使って色空間を取得してRGB とRGBAの時でglTexImage2Dの引数が変わるので色空間を取得したいのですがどうすればいいのでしょうか?調べましたが出てきません。
cpp
1 2class Game; 3/*################################################################################################################ 4* 画像 描画クラス 5################################################################################################################*/ 6 7//コンストラクタ 8Sprite::Sprite(Game* g, const char* FileName,glm::vec2 start,glm::vec2 size) : Transform_2D() 9{ 10 shader = new Shader(g,"Shader/2D/Sprite.vert", "Shader/2D/Sprite.frag"); 11 Owner = g;//Gameクラス 12 13 mSize.x = size.x - start.x; 14 mSize.y = size.y - start.y; 15 16 //テクスチャを設定 17 glGenTextures(1, &TextureID); 18 glBindTexture(GL_TEXTURE_2D, TextureID); 19 20 21 22 23 /* 24 int width, height; 25 int numComponents; 26 unsigned char* data = stbi_load(FileName, &width, &height, &numComponents, 4); 27 if (data != NULL) { 28 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 29 } 30 else { 31 std::cerr << "Unable to load texture: " << FileName << std::endl; 32 } 33 */ 34 35 36 37 int width, height; 38 int numComponents; 39// unsigned char* data = stbi_load(FileName, &width, &height, &numComponents, 4); 40 unsigned char* data = Owner->LoadTexture(FileName,&width,&height); 41/////////////////////////////////////////////////////////////////////////////////////////////////////////// 42 if (data != NULL) 43 { 44 printf("いい\n"); 45 // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void*)data); 46 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 47 printf("ああ\n"); 48 49 } 50 else { 51 std::cerr << "Unable to load texture: " << FileName << std::endl; 52 } 53/////////////////////////////////////////////////////////////////////////////////////////////////////////// 54 55 56 57 58 59 60 61 62 float uvWidth = 1.0f / (float)width; 63 float uvHeight = 1.0f / (float)height; 64 65 vertex[0] = attribute{ -(float)(size.x ) / 2.0f , (float)(size.y) / 2.0f , uvWidth * start.x, uvHeight * start.y}; 66 vertex[1] = attribute{ -(float)(size.x ) / 2.0f , -(float)(size.y) / 2.0f , uvWidth * start.x, (uvHeight * start.y) + (uvHeight * size.y)}; 67 vertex[2] = attribute{ (float)(size.x ) / 2.0f, -(float)(size.y) / 2.0f , (uvWidth * start.x) + (uvWidth * size.x),(uvHeight * start.y) + (uvHeight * size.y) }; 68 vertex[3] = attribute{ (float)(size.x ) / 2.0f , (float)(size.y) / 2.0f , (uvWidth * start.x) + (uvWidth * size.x), uvHeight * start.y }; 69 70 //VAO 71 glGenVertexArrays(1, &VAO); 72 glBindVertexArray(VAO); 73 74 //VBO 75 glGenBuffers(1, &VBO); 76 glBindBuffer(GL_ARRAY_BUFFER, VBO); 77 glBufferData(GL_ARRAY_BUFFER, (sizeof(vertex) / sizeof(vertex[0])) * sizeof(attribute), vertex, GL_STATIC_DRAW); 78 79 //頂点座標 80 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(attribute), NULL); 81 glEnableVertexAttribArray(0); 82 83 //UV座標 84 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(attribute), (void*)(sizeof(float) * 2)); 85 glEnableVertexAttribArray(1); 86 87 //IBO 88 glGenBuffers(1, &IBO); 89 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); 90 glBufferData(GL_ELEMENT_ARRAY_BUFFER, (sizeof(index) / sizeof(index[0])) * sizeof(unsigned int), index, GL_STATIC_DRAW); 91 92 //ミニマップを設定 93 glGenerateMipmap(GL_TEXTURE_2D); 94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 96 97 //異方性フィルタリングを設定 98 GLfloat largest; 99 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest); 100 101 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest); 102 103 stbi_image_free(data); 104} 105
回答1件
あなたの回答
tips
プレビュー