English 中文(简体)
Aggravating OpenGL Texture Issue
原标题:

I m having issues trying to get a texture loaded into VRAM. I m using OpenGL on Mac OS X. I have geometry that I ve successfully renderer by passing a color into my fragment shader. However, as soon as I try to load a texture, no geometry gets rendered and I can only see the background color. Here s my texture loading code:

char imageData[27] = {
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
    127, 127, 127,
};

glActiveTexture(GL_TEXTURE0);
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 3, 3, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);

GLint uniform_location = glGetUniformLocation(bundle->GetShaderProgramID(), "texture");
std::cout << uniform_location <<std::endl;
glUniform1i(uniform_location, 0);

glEnable(GL_TEXTURE_2D);

And here s my fragment shader code:

uniform sampler2D texture;

void main()
{
    vec2 coord = vec2(0.5, 0.5);

    //gl_FragColor = vec4(coord, 0.0, 1.0);

    gl_FragColor = vec4(texture2D(texture, coord).rgb, 1.0);
}

I realize some of this code probably isn t necessary, but I ve been trying everything I can think of.

Thanks.

最佳回答

The most likely cause is that you don t have mipmapping off, and you did not specify mipmapping levels. So your texture is incomplete.

To turn it off on this texture object (to be done around the glTexImage2D call)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

You do however realize that "everything breaks down" does not help at all figuring out what you see ? In general, a screenshot is worth a thousand words, but short of that, at least describing how it fails would help.

问题回答

暂无回答




相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签