Sign in to follow this  

declaring a type

This topic is 3573 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

i have this code its a bit long but here it is: #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); 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(); }; So when i try to have bool Initialize(); in the CGfxOpenGL.h file it says that Initialize is not a type, as well as the Skybox.Render you see above. The Initialize is part of the Skybox.Initialize function and dont know what or where to put it to make it work. Any help would be greatly appreciated! Thanks!

Share this post


Link to post
Share on other sites
errors:
Compiler: Default compiler
Building Makefile: "C:\ATimetoKill\Makefile.win"
Executing make...
make.exe -f "C:\ATimetoKill\Makefile.win" all
g++.exe -c CGfxOpenGL.cpp -o CGfxOpenGL.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -g3 -O0

CGfxOpenGL.cpp: In member function `bool CGfxOpenGL::Init()':
CGfxOpenGL.cpp:60: error: `Initialize' has not been declared
CGfxOpenGL.cpp:60: error: request for member of non-aggregate type before '(' token
CGfxOpenGL.cpp:61: error: `LoadTextures' has not been declared
CGfxOpenGL.cpp:61: error: request for member of non-aggregate type before '(' token
CGfxOpenGL.cpp: In member function `bool CGfxOpenGL::Shutdown()':
CGfxOpenGL.cpp:74: error: `Release' has not been declared
CGfxOpenGL.cpp:74: error: request for member of non-aggregate type before '(' token

CGfxOpenGL.cpp: At global scope:
CGfxOpenGL.cpp:156: error: no `void CGfxOpenGL::Render()' member function declared in class `CGfxOpenGL'
CGfxOpenGL.cpp: In member function `void CGfxOpenGL::Render()':
CGfxOpenGL.cpp:164: error: `Render' has not been declared
CGfxOpenGL.cpp:164: error: request for member of non-aggregate type before '(' token

make.exe: *** [CGfxOpenGL.o] Error 1

Execution terminated

Share this post


Link to post
Share on other sites
What's the header Skybox.h look like? And the header for whatever class you're implementing here?

Does CGfxOpenGL have a member named Skybox? If not, that's your problem. Otherwise you may be trying to call a static method incorrectly (use Skybox::Initialize()). Et cetera.

But basically, we need to see more code to be sure.

Share this post


Link to post
Share on other sites


#ifndef __SKYBOX_H_INCLUDED__
#define __SKYBOX_H_INCLUDED__
class Skybox;

class CSkybox
{
public:
CSkybox();
~CSkybox();

void Initialize(float size);
bool LoadTextures(char* top, char* bottom, char* front, char* back, char* left, char* right);
void Render(float cameraX, float cameraY, float cameraZ);
void Release();

enum {
SKY_TOP,
SKY_BOTTOM,
SKY_FRONT,
SKY_BACK,
SKY_LEFT,
SKY_RIGHT
};

protected:
unsigned int m_textures[6]; // 6 texture objects
float m_size;
};

#endif // __SKYBOX_H_INCLUDED__


Share this post


Link to post
Share on other sites


#ifndef __GL_COMPONENT
#define __GL_COMPONENT

const int TERRAIN_SIZE = 260;

#define PI 3.14159f
#define DEG2RAD(x) (x*PI)/180.0f

class CSkybox;

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 Skybox;
bool Init();
bool Shutdown();
void SetupProjection(int width, int height);

void Prepare(float dt);


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


Share this post


Link to post
Share on other sites
Are there two sky boxes? one with a wart and one without?

#ifndef __SKYBOX_H_INCLUDED__
#define __SKYBOX_H_INCLUDED__
class Skybox;

class CSkybox

Share this post


Link to post
Share on other sites
all of the Skybox functions are within the blocks of bool CGfxOpenGL::Init(); and void CGfxOpenGL::Render(); etc

So if i have Skybox.Render(); and its in void CGfxOpenGL::Render(); what would i need to have in the Skybox Header?

class Skybox
{
public:
void Render();
}

// that doesnt work :(

i've tried including them under the CGfxOpenGL.h in that very same way, but it wont work. :(

bool Skybox; in the CGfxOpenGL under public is what made me go a step further.
bool typedef Initialize(); declares it, but the compiler says that it is a non aggregate type before ( tokens.

Share this post


Link to post
Share on other sites

This topic is 3573 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