Quote:Original post by mr_mo
Quote:// Begin GL
Gl.glBegin(Gl.GL_QUADS);
// Upper Left Corner
//Gl.glTexCoord2f(.25F, .125F);
//Gl.glVertex(0.0F, 30.0F, 0.0F);
Gl.glTexCoord2d(0, 1024);
Gl.glVertex2d(0, 0);
// End
Gl.glEnd();
texture coordinates are from 0 to 1. Did you really mean 1024 (repeated textures 1023 times)??
You only have on vertex being drawn for a quad that needs 4 vertcies?
<snip>
I've read that texture coordinates must mirror vertex coordinates and so upper becomes lower and left becomes right, is this right?
No? They don't
have to, and normally don't if you're trying to see your picture right-side-up. They can, but I don't think you want them to. You may be confusing this with window coordinates (in Windows) and OpenGL's coordinate systems, but that's only on the y axis.
Quote:I've updated my original post with correct code. I'm sorry for the confusion.
You don't seem to have fixed what dpadam450 pointed out - you really only want to use texture coordinates 0.0 and 1.0. These are the lower and upper values for either edge of your texture, OpenGL could (at this point) care less about what exact texels you want to see, it cares about what fraction of the texture you want to see. Normally, OpenGL will generate
mipmaps for you, which throws the idea of "give me texel 'x,y'" right out the window. Instead, you want to say "give me region 'x/width,y/height' of my texture," which will apply the appropriate part of the texture to your primitive. As you can see, this number will usually be in the range 0..1 for values of x and y within the texture. However, specifying a larger number can have different effects. Depending on how you have things set up, it will either repeat the texture, or clamp the value to the edge of the texture. In the latter case, you'll end up with one tiny version of your texture in one corner (lower left if you haven't applied any transformations) with bands extending up and to the right containing the contents of the upper and right edges of the texture, respectively. Once you have it loading correctly, try changing the necessary parameters:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP); Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP);
and you'll see what I mean.
Also, you don't want to call Gl.glGenTextures(1, out texture); every frame, just once when you're loading the texture. It makes space for a new texture object, so you're just leaving the one you already loaded in memory somewhere, and causing texture to point to a newly created empty blob of nothing.
So, for now, change to this and see if it works:
/// <summary> /// Render the screen. /// </summary> protected virtual void RenderScreen() { Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glLoadIdentity(); // Enable 2D Enable2D(); // Create Texture // Note: this doesn't create a texture, just reserves space for one. // since you never come back and create one, you're applying a blank texture. // Gl.glGenTextures(1, out texture); // Enable GL // Note: these are for testing, I guess? You don't need them here, especially since the first overrides the first two.... Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_REPLACE); Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_BLEND); Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE); Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); // Begin GL Gl.glBegin(Gl.GL_QUADS); // Upper Left Corner - (actually lower left, you seem to have flipped everything in Y) Gl.glTexCoord2d(0, 0); Gl.glVertex2d(0, 0); // Upper Right Corner - (again, actually lower right) Gl.glTexCoord2d(1, 0); Gl.glVertex2d(256, 0); // Lower Left Corner // Does this winding produce a proper quad? I've never tried drawing a quad out of order before... // Usually, the ordering of vertices for a quad is to just trace around the perimeter counter-clockwise (in OpenGL) // i.e. ll, lr, ur, ul Gl.glTexCoord2d(0, 1); Gl.glVertex2d(0, 1024); // Lower Rigt Corner Gl.glTexCoord2d(1, 0); Gl.glVertex2d(256, 1024); // End Gl.glEnd(); // Disable 2D Disable2D(); }
If it still doesn't work, try swapping the last two vertex/texcoord pairs to have the indicated winding. If it still doesn't work, post back! [smile]