I wish to bind a texture on a cube (creating cube using GlutSolidCube and not glvertex) but the whole texture is bound. In the image file I have all textures together (for speed and because the teacher requested) and I only want part of the texture to be bound. How can I do that????
Textures are the unit of texture binding. If you want to "cut out" part of a texture, you do so by adjusting the texture coordinates that you use.
Instead of using the full range of 0..1, use smaller values that match the sub-texture's location inside the texture.
What you're looking to do is not possible, because glutSolidCube does not generate texture coordinates.
However, you will also note that an answer to that question indicates that you may use the following to have OpenGL generate texture coordinates for you on a call to glutSolidCube:
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
Some more information on using OpenGL's automatic texture coordinate generation is available here. However, I would like to note that this seems to come out of the days of immediate-mode OpenGL, which is deprecated. Also, GLUT is no longer maintained, but freeglut is.
To summarize, you're better off using glVertex calls and specifying your own specific texture coordinates, as unwind has suggested. You can try OpenGL's texture coordinate generation, but it might be too strict to handle what you need.
Related
I am actually surprised that the OpenGL Docs say that this is possible, since it doesn't give any information on how to actually call glGetTexImage for a cubemap texture array. Is this actually possible?
It looks like glGetTextureSubImage is built for this, but that is unfortunately not supported in OpenGL 4.3, which I'm using. Surely there most be a way to achieve this that's not such a recent addition to the API.
I am actually surprised that the OpenGL Docs say that this is possible
It does not say that. You can retrieve a mipmap level from a cubemap array, just like you can for a 2D array, or a 3D texture. But this means getting all faces of every layer for that mipmap level, just as it does for 2D arrays and 3D textures.
If you want only one face from only one layer (which you can do for a non-array cubemap by using one of the face targets), then you will need to isolate this layer/face from the cubemap array. Specifically, you need to create a 2D view texture of the cubemap array that includes only that layer/face. You can perform glGetTexImage from that.
I have already tried and succeeded loading a texture from a bmp file, and drawing quads and triangles with texture. However i need to apply the loaded texture to an object drawn with glutSolidDodecahedron and glutSolidSphere. How can i do this? Please include some code if possible
Note: I HAVE to use those functions, I'm not allowed to draw them from scratch.
Neither glutSolidDodecahedron nor glutSolidSphere specifies texture coordinates, at least not according to any documentation that a quick web search turns up. I had a quick look at the FreeGLUT implementations and those do indeed not specify texture coordinates.
If you can use shaders, you can derive the 2D texture coordinates from the 3D location of the vertices. Spheres and dodecahedrons are pretty regular shapes, so you can simply do a spherical projection (convert the vertex position to spherical coordinates and drop the radius component).
Lets say i have an application ( the details of the application should be irrelevent for solving the problem ). Instead of rendering to the screen, i am somehow able to force the application to render to a framebuffer object instead of rendering to the screen ( messing with glew or intercepting a call in a dll ).
Once the application has rendered its content to the FBO is it possible to apply a shader to the contents of the FB? My knowledge is limited here, so from what i understand at this stage all information about vertices is no longer available and all the necessary tests have been applied, so whats left in the buffer is just pixel data. Is this correct?
If it is possible to apply a shader to the FBO, is is possible to get a fisheye affect? ( like this for example: http://idea.hosting.lv/a/gfx/quakeshots.html )
The technique used in the linke above is to create 6 different viewports and render each viewport to a cubemap face and then apply the texture to a mesh.
Thanks
A framebuffer object encapsulates several other buffers, specifically those that are implicitly indexed by fragment location. So a single framebuffer object may bundle together a colour buffer, a depth buffer, a stencil buffer and a bunch of others. The individual buffers are known as renderbuffers.
You're right — there's no geometry in there. For the purposes of reading back the scene you get only final fragment values, which if you're highjacking an existing app will probably be a 2d pixel image of the frame and some other things that you don't care about.
If your GPU has render-to-texture support (originally an extension circa OpenGL 1.3 but you'd be hard pressed to find a GPU without it nowadays, even in mobile phones) then you can link a texture as a renderbuffer within a framebuffer. So the rendering code is exactly as it would be normally but ends up writing the results to a texture that you can then use as a source for drawing.
Fragment shaders can programmatically decide which location of a texture map to sample in order to create their output. So you can write a fragment shader that applies a fisheye lens, though you're restricted to the field of view rendered in the original texture, obviously. Which would probably be what you'd get in your Quake example if you had just one of the sides of the cube available rather than six.
In summary: the answer is 'yes' to all of your questions. There's a brief introduction to framebuffer objects here.
Look here for some relevant info:
http://www.opengl.org/wiki/Framebuffer_Object
The short, simple explanation is that a FBO is the 3D equivalent of a software frame buffer. You have direct access to individual pixels, instead of having to modify a texture and upload it. You can get shaders to point to an FBO. The link above gives an overview of the procedure.
This is for a 2D game with OpenGL:
Is it with using OpenGL possible to display a texture absolutely unfiltered, not streched or blurred?
So that when I have a BMP and convert it into an OpenGL texture, and then retrieve that texture and convert it back, I have no modifications or quality / data loss?
Sure, just disable filtering, that's made by setting the GL_MIN_FILTER and the GL_MAG_FILTER to GL_NEAREST. Also make sure that you draw the texture in a appropiate size so that texels are the same size as pixels.
As Matias said previously - one thing is to set GL_MIN_FILTER and GL_MAG_FITLER to GL_NEAREST (via glTexParameter*).
But for pixel-perfect rendering, there's another important thing- you don't want your texture to be rescaled to power-of-two. The easiest way is to specify the texture via the binding target GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D. On such bound texture, the texture coordinates are not in range (0..1,0..1) as usually, but (0..w, 0..h) instead. You can have per-texel indexing easily this way.
I'm having a problem getting accurate primitive colours when I'm using multi-texturing elsewhere in the scene. Basically, I have some lines and polygons that I am trying render over a video texture (I'm using 3 stage multitexturing to create the video texture)... Anyhow, I know the problem is not alpha related... In fact, I know that in my texture update function if I just comment out the calls to glBindTexture() for texture levels 1 and 2, the primitive color is fine (so leaving texture level 0)... Is it trying to multitexture the primitives too (even though I'm obviously not setting texture coordinates for primitives)?
Make sure to disable multitexturing when not using it. OpenGL uses a state machine, so if you turn on a texture it will stay on until you explicitly turn it off.
Just because you're not setting coordinates, doesn't mean OpenGL will assume you're not using the texture.