Currently I create my 3D models using following code (simplified):
gl3Element->shaderProgram=glCreateProgram();
glAttachShader(gl3Element->shaderProgram,m_gl3VertexShader);
glAttachShader(gl3Element->shaderProgram,m_gl3DynColourFragmentShader);
glLinkProgram(gl3Element->shaderProgram);
glDeleteShader(m_gl3VertexShader);
glDeleteShader(m_gl3DynColourFragmentShader);
glGenVertexArrays(1, &gl3Element->VAO);
glGenBuffers(1, &gl3Element->VBO);
glBindVertexArray(entity->m_gl3Element.VAO);
glBindBuffer(GL_ARRAY_BUFFER,entity->m_gl3Element.VBO);
glBufferData(GL_ARRAY_BUFFER,size,data,GL_STATIC_DRAW);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// todo: add texture code here?
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
My current (not working) texture code looks like this:
glGenTextures(1, &imgEntity->m_glTexture);
glBindTexture(GL_TEXTURE_2D, imgEntity->m_glTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,transImage->GetWidth(),transImage->GetHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,transImage->GetData());
glBindTexture(GL_TEXTURE_2D, imgEntity->m_glTexture);
The things that are missing obviously are texture coordinates and assignment of the texture to the created model. So my questions:
How can I apply some valid texture coordinates to the object using only OpenGL 3.0 and GLSL 1.3?
How do I assign these texture data to the model so that they are drawn on my next call to
glBindVertexArray(element->VAO);
glDrawArrays(element->arrayType,arrayStart,element->arraySize);
for this model ?
Thanks!
glVertexAttribPointer/glEnableVertexAttribArray). See the following tutorial Textures objects and parameters. But usually this question is to broad. - Rabbid76