Archived

This topic is now archived and is closed to further replies.

Sky Box!!

This topic is 5644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey, I know that this subject has been up several times and I have looked through many of the previous posts, but in my case they didn't help at all... Once again it is the interpolation between the textures, spoiling my skybox... I have tried both GL_CLAMP and GL_CLAMP_TO_EDGE... and I have tried to disable depth-testing, alpha-testing, pushing with the matrix stack, but it dosn't help me much... Here is my code ->
GLvoid DrawSkyBox(GLfloat x, GLfloat y, GLfloat z, GLfloat bWidth, GLfloat bHeight, GLfloat bLength, CVector3 *bVertices){

glEnable(GL_TEXTURE_2D);

CVector2 bTexCoords[24];

// Define The Back Side Of The Sky Box

bTexCoords[0]	= CVector2(0.0f, 1.0f);
bVertices[0]	= CVector3(x - bWidth, y - bHeight, z - bLength);
bTexCoords[1]	= CVector2(1.0f, 1.0f);
bVertices[1]	= CVector3(x + bWidth, y - bHeight, z - bLength);
bTexCoords[2]	= CVector2(1.0f, 0.0f);
bVertices[2]	= CVector3(x + bWidth, y + bHeight, z - bLength);
bTexCoords[3]	= CVector2(0.0f, 0.0f);
bVertices[3]	= CVector3(x - bWidth, y + bHeight, z - bLength);

// Define The Front Side Of The Sky Box

bTexCoords[4]	= CVector2(1.0f, 1.0f);
bVertices[4]	= CVector3(x - bWidth, y - bHeight, z + bLength);
bTexCoords[5]	= CVector2(1.0f, 0.0f);
bVertices[5]	= CVector3(x - bWidth, y + bHeight, z + bLength);
bTexCoords[6]	= CVector2(0.0f, 0.0f);
bVertices[6]	= CVector3(x + bWidth, y + bHeight, z + bLength);
bTexCoords[7]	= CVector2(0.0f, 1.0f);
bVertices[7]	= CVector3(x + bWidth, y - bHeight, z + bLength);

// Define The Bottom Side Of The Sky Box

bTexCoords[8]	= CVector2(0.0f, 1.0f);
bVertices[8]	= CVector3(x - bWidth, y - bHeight, z + bLength);
bTexCoords[9]	= CVector2(1.0f, 1.0f);
bVertices[9]	= CVector3(x + bWidth, y - bHeight, z + bLength);
bTexCoords[10]	= CVector2(1.0f, 0.0f);
bVertices[10]	= CVector3(x + bWidth, y - bHeight, z - bLength);
bTexCoords[11]	= CVector2(0.0f, 0.0f);
bVertices[11]	= CVector3(x - bWidth, y - bHeight, z - bLength);

// Define The Top Side Of The Sky Box

bTexCoords[12]	= CVector2(0.0f, 1.0f);
bVertices[12]	= CVector3(x - bWidth, y + bHeight, z + bLength);
bTexCoords[13]	= CVector2(0.0f, 0.0f);
bVertices[13]	= CVector3(x - bWidth, y + bHeight, z - bLength);
bTexCoords[14]	= CVector2(1.0f, 0.0f);
bVertices[14]	= CVector3(x + bWidth, y + bHeight, z - bLength);
bTexCoords[15]	= CVector2(1.0f, 1.0f);
bVertices[15]	= CVector3(x + bWidth, y + bHeight, z + bLength);

// Define The Left Side Of The Sky Box

bTexCoords[16]	= CVector2(1.0f, 1.0f);
bVertices[16]	= CVector3(x - bWidth, y - bHeight, z - bLength);
bTexCoords[17]	= CVector2(1.0f, 0.0f);
bVertices[17]	= CVector3(x - bWidth, y + bHeight, z - bLength);
bTexCoords[18]	= CVector2(0.0f, 0.0f);
bVertices[18]	= CVector3(x - bWidth, y + bHeight, z + bLength);
bTexCoords[19]	= CVector2(0.0f, 1.0f);
bVertices[19]	= CVector3(x - bWidth, y - bHeight, z + bLength);

// Define The Right Side Of The Sky Box

bTexCoords[20]	= CVector2(0.0f, 1.0f);
bVertices[20]	= CVector3(x + bWidth, y - bHeight, z - bLength);
bTexCoords[21]	= CVector2(1.0f, 1.0f);
bVertices[21]	= CVector3(x + bWidth, y - bHeight, z + bLength);
bTexCoords[22]	= CVector2(1.0f, 0.0f);
bVertices[22]	= CVector3(x + bWidth, y + bHeight, z + bLength);
bTexCoords[23]	= CVector2(0.0f, 0.0f);
bVertices[23]	= CVector3(x + bWidth, y + bHeight, z - bLength);

for (GLuint i = 0; i < 24; i += 4){

glBindTexture(GL_TEXTURE_2D, skyBoxTextures[(i / 4)]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexCoord2f(bTexCoords[i].x, bTexCoords[i].y);
glVertex3f(bVertices[i].x, bVertices[i].y, bVertices[i].z);
glTexCoord2f(bTexCoords[(i + 1) % 24].x, bTexCoords[(i + 1) % 24].y);
glVertex3f(bVertices[(i + 1) % 24].x, bVertices[(i + 1) % 24].y, bVertices[(i + 1) % 24].z);
glTexCoord2f(bTexCoords[(i + 2) % 24].x, bTexCoords[(i + 2) % 24].y);
glVertex3f(bVertices[(i + 2) % 24].x, bVertices[(i + 2) % 24].y, bVertices[(i + 2) % 24].z);
glTexCoord2f(bTexCoords[(i + 3) % 24].x, bTexCoords[(i + 3) % 24].y);
glVertex3f(bVertices[(i + 3) % 24].x, bVertices[(i + 3) % 24].y, bVertices[(i + 3) % 24].z);

glEnd();
}

glDisable(GL_TEXTURE_2D);
}

and the draw to the screen code ->

GLvoid DrawGLScreen(){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

gCamera.SetView();
gCamera.SetViewByMouse();

CVector3 bVertices[24];
DrawSkyBox(0.0f, 0.0f, 0.0f, 2000.0f, 2000.0f, 2000.0f, bVertices);

SwapBuffers(wOpenGL.hDC);
}

Share on other sites
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

I think these are required before creating the texture.
so in your texture load code put those two lines after binding the texture

Share on other sites
you set them when you create your texture and have bound the texture

Share on other sites
Hey again... thx for the replies, but it either of them did work

bool CreateTexture(char *fileName, GLuint textureArray[], GLuint textureID){

// If No File Name Is Given - Return
if (!fileName)
return false;

// The Texture Struct And File Holder
STextureTGA *iTGA = NULL;
FILE *fileTGA;

// If The File Won''t Open - Return
if (!(fileTGA = fopen(fileName, "rb")))
return false;

// Allocate Memory For The Struct
iTGA = new STextureTGA;

// If The Allocation Failed - Close The File And Return
if (!iTGA){

fclose(fileTGA);
return false;
}

// If The Image Can''t Be Loaded - Free The Memory, Close The File And Return

delete[] iTGA;
fclose(fileTGA);
return false;
}

// Generate The Texture
glGenTextures(1, &textureArray[textureID]);
// Bind It
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
// Build It
gluBuild2DMipmaps( GL_TEXTURE_2D, iTGA->iChannels, iTGA->iWidth,
iTGA->iHeight, iTGA->iType, GL_UNSIGNED_BYTE, iTGA->iData);

// Set The Quality Of The Texture Map
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Free The Memory
delete[] iTGA->iData;
delete[] iTGA;

// Return True
return true;
}

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• Forum Statistics

• Total Topics
633348
• Total Posts
3011462

×