Sign in to follow this  

declaring skybox.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

alright well i dont think i need a new class for these functions: Originally they were skybox.Release and so on. But i had a problem with the . macro so i renamed them to Skybox_Release. So im stummped on how to get this functions declared in the header file. heres the code #ifndef __GL_COMPONENT #define __GL_COMPONENT const int TERRAIN_SIZE = 260; #define PI 3.14159f #define DEG2RAD(x) (x*PI)/180.0f class Skybox; class CGfxOpenGL { private: GLubyte heightmap[TERRAIN_SIZE * TERRAIN_SIZE]; int m_windowWidth; int m_windowHeight; GLuint m_grassTexture; GLuint m_waterTexture; float m_angle; float m_height; float cameraX, cameraY, cameraZ; public: CGfxOpenGL(); virtual ~CGfxOpenGL(); bool Init(); bool Shutdown(); void SetupProjection(int width, int height); void Prepare(float dt); void Render(); void MoveCameraRight() { m_angle += 3.0f; } void MoveCameraLeft() { m_angle -= 3.0f; } void MoveCameraUp() { m_height += 3.0f; } void MoveCameraDown() { m_height -= 3.0f;} void DrawTerrain(); }; #endif [/source] now obiviosly this is the header file where i should be able to declare the functions. Anyhelp would be much appreciated. And the Skybox header is perfect i dont need to change anything. Here is the CGfxOpenGL code to help u help me (if ya dont mind :))


#ifdef _WINDOWS
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
#include <time.h>
#include "glext.h"
#include "CGfxOpenGL.h"
#include <cmath>
#include <cstdio>
#include "CTargaImage.h"
#include <Skybox.h>

#pragma warning(disable:4244)

const char heightmapFilename[] = "heightmap.raw";
const float MAX_HEIGHT = 30.0f;
const float MAX_FOG_HEIGHT = MAX_HEIGHT * 0.5f;
const float SCALE_FACTOR = 256.0f / MAX_HEIGHT;
const float WATER_HEIGHT = 2.0f;

CGfxOpenGL::CGfxOpenGL()
{
   m_grassTexture = m_waterTexture = 0;
   cameraX = cameraY = cameraZ = 0.0f;
   m_angle = 0.0;
   m_height = 10.0;
}


CGfxOpenGL::~CGfxOpenGL()
{
}

bool CGfxOpenGL::Init()
{	
	FILE *pFile = fopen(heightmapFilename, "rb");
	if(!pFile)
       return false;

	fread(&heightmap, TERRAIN_SIZE * TERRAIN_SIZE, 1, pFile);
	fclose(pFile);
	CTargaImage image;
	
	image.Load("grass.tga");
	glGenTextures(1, &m_grassTexture);
	glBindTexture(GL_TEXTURE_2D, m_grassTexture);
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.GetWidth(), image.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, image.GetImage());
	image.Release();
	
	image.Load("water.tga");
	glGenTextures(1, &m_waterTexture);
	glBindTexture(GL_TEXTURE_2D, m_waterTexture);
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.GetWidth(), image.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, image.GetImage());
	image.Release();

    Skybox_Initialize(10.0);
    Skybox_LoadTextures("up.tga", "dn.tga", "ft.tga", "bk.tga", "lt.tga", "rt.tga");
	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	
	return true;
}

bool CGfxOpenGL::Shutdown()
{
	glDeleteTextures(1, &m_waterTexture);
	glDeleteTextures(1, &m_grassTexture);
    int Skybox_Release();
	Skybox_Release();
	
	return true;
}

void CGfxOpenGL::SetupProjection(int width, int height)
{
	if (height == 0)					// don't want a divide by zero
	{
		height = 1;					
	}

	glViewport(0, 0, width, height);		// reset the viewport to new dimensions
	glMatrixMode(GL_PROJECTION);			// set projection matrix current matrix
	glLoadIdentity();						// reset projection matrix

	// calculate perspective
	gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);

	glMatrixMode(GL_MODELVIEW);				// set modelview matrix
	glLoadIdentity();						// reset modelview matrix

	m_windowWidth = width;
	m_windowHeight = height;
}

void CGfxOpenGL::Prepare(float dt)
{
     cameraX = sin(DEG2RAD(m_angle))*TERRAIN_SIZE/2.0f;
     cameraY = m_height;
     cameraZ = cos(DEG2RAD(m_angle))*TERRAIN_SIZE/2.0f;
}

void CGfxOpenGL::DrawTerrain()
{
	// draw terrain!
	
	glBindTexture(GL_TEXTURE_2D, m_grassTexture);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	for (int z = 0; z < TERRAIN_SIZE - 1; ++z)
	{
        glBegin(GL_TRIANGLE_STRIP);
        for (int x = 0; x < TERRAIN_SIZE - 1; ++x)
        {
            // render two vertices on the same strip at once
            float scaledHeight = heightmap[z * TERRAIN_SIZE + x] / SCALE_FACTOR;
            float nextScaledheight = heightmap[(z + 1) * TERRAIN_SIZE + x] / SCALE_FACTOR;
            float color = 0.5f + 0.5f * scaledHeight / MAX_HEIGHT;
            float nextColor = 0.5 + 0.5f * nextScaledheight / MAX_HEIGHT;
	
	        glColor3f(color, color, color);
	        glTexCoord2f((GLfloat)x/TERRAIN_SIZE*8, (GLfloat)z/TERRAIN_SIZE*8);
	        glVertex3f(static_cast<GLfloat>(x - TERRAIN_SIZE/2), scaledHeight, static_cast<GLfloat>(z - TERRAIN_SIZE/2));
	        
	        glColor3f(nextColor, nextColor, nextColor);
	        glTexCoord2f((GLfloat)x/TERRAIN_SIZE*8, (GLfloat)(z+1)/TERRAIN_SIZE*8);
	        glVertex3f(static_cast<GLfloat>(x - TERRAIN_SIZE/2), scaledHeight, static_cast<GLfloat>(z + 1 - TERRAIN_SIZE/2));
         }
         glEnd();
}

         // draw the water
    glBindTexture(GL_TEXTURE_2D, m_waterTexture);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glBegin(GL_QUADS);
          glTexCoord2f(0.0f, 0.0f);
          glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);
          
          glTexCoord2f(TERRAIN_SIZE/4.0f, 0.0f);
          glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);
          
          glTexCoord2f(TERRAIN_SIZE/4.0f, 0.0f);
          glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);
          
          glTexCoord2f(0.0f, TERRAIN_SIZE/4.0f);
          glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);
          
    glEnd();

} 
         
void CGfxOpenGL::Render()
{
     glClearColor(0.0f, 0.0, 0.0, 0.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     glLoadIdentity();
     gluLookAt(cameraX, cameraY, cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     
     // skybox origin should be same as camera position
   
   Skybox_Render(cameraX, cameraY, cameraZ);
     
     DrawTerrain();
};

could u PLEASE help im really exited on building some more vectors.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this