Menu

skybox

starcreek
2008-02-20
2012-09-26
  • starcreek

    starcreek - 2008-02-20

    i would really like to know how to declare m_skybox.Initialize() in the header file.

    i tried having a new class with specific varaible names. So far i have

    class m_skybox
    {
    public:

    m_skybox();
    virtual ~m_skybox();

    void Initialize ( void );
    };
    // right here i would want to implement the function?
    void m_skybox::Initialize( void )

    int main()
    {
    m_skybox varaibleName;
    variableName.Initialize();
    }

    But it just gives me the same errors that i already have. Could you help please?

    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:62: error: expected primary-expression before '.' token
    CGfxOpenGL.cpp:63: error: expected primary-expression before '.' token

    CGfxOpenGL.cpp: In member function `bool CGfxOpenGL::Shutdown()':
    CGfxOpenGL.cpp:76: error: expected primary-expression before '.' token

    CGfxOpenGL.cpp: In member function `void CGfxOpenGL::Render()':
    CGfxOpenGL.cpp:166: error: expected primary-expression before '.' token

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

    Execution terminated

     
    • cpns

      cpns - 2008-02-28

      I told you the answer. It seems that you still don't understand. You are a lost cause.

       
    • cpns

      cpns - 2008-02-21

      The errors reported in the log bear no obvious relationship to the code you posted, ther refer to an entirely different functions in a different class.

      Try reading teh error messages!

      For example in CGfxOpenGL.cpp at line 62 (in the CGfxOpenGL::Init() function), I reckon it is a fair bet that whatever you have before the '.' is not a primary expression! i.e. whatever the left-hand-side evaluates to is not something for which the member operator makes any sense.

      Unless you post the code that the log is referring to, we cannot help you.

      With respect to the m_skybox::Initialize() function:

      void m_skybox::Initialize( void )
      {
      // function body here.
      }

      What kind of naming convention does m_skybox adhere too!? The prefix m_ is most often used to indicate class member variables. Why not cSkybox?

      Clifford

       
    • starcreek

      starcreek - 2008-02-27

      ok i have tired many times at an attempt to what i thought would work but it hasnt.

      so heres the code:

      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(&amp;heightmap, TERRAIN_SIZE * TERRAIN_SIZE, 1, pFile);
      fclose(pFile);
      
      CTargaImage image;
      
      image.Load(&quot;grass.tga&quot;);
      glGenTextures(1, &amp;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(&quot;water.tga&quot;);
      glGenTextures(1, &amp;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();
      
      m_skybox.Initialize(10.0);    // these are the types that i have problems declaring in the Skybox.h but i do believe that they should be defined in the CGfxOpenGL.h because of what the error log states
      m_skybox.LoadTextures(&quot;up.tga&quot;, &quot;dn.tga&quot;, &quot;ft.tga&quot;, &quot;bk.tga&quot;, &quot;lt.tga&quot;, &quot;rt.tga&quot;);
      
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_TEXTURE_2D);
      
      return true;
      

      }

      bool CGfxOpenGL::Shutdown()
      {
      glDeleteTextures(1, &m_waterTexture);
      glDeleteTextures(1, &m_grassTexture);

      m_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 &lt; TERRAIN_SIZE - 1; ++z)
      {
          glBegin(GL_TRIANGLE_STRIP);
          for (int x = 0; x &lt; 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&lt;GLfloat&gt;(x - TERRAIN_SIZE/2), scaledHeight, static_cast&lt;GLfloat&gt;(z - TERRAIN_SIZE/2));
      
              glColor3f(nextColor, nextColor, nextColor);
              glTexCoord2f((GLfloat)x/TERRAIN_SIZE*8, (GLfloat)(z+1)/TERRAIN_SIZE*8);
              glVertex3f(static_cast&lt;GLfloat&gt;(x - TERRAIN_SIZE/2), scaledHeight, static_cast&lt;GLfloat&gt;(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
      m_skybox.Render(cameraX, cameraY, cameraZ);
      
       DrawTerrain();
      

      };

      so how would i go about including these statements into the header file(s)?
      should i go about renaming m_skybox.Intialize() to cSkybox.Intialize() which unsurprisinly gave me the same result.

       
    • cpns

      cpns - 2008-02-27

      It has been said before that you are being too ambitious. You have obviously not grasped the basics of C++.

      In your code m_skybox is a (badly nemed) data type, despite being named like a variable. In that context the statement:

      m_skybox.Initialize(10.0);

      makes no sense, the symbol on teh left-hand-side of the dot must represent a data instance not a data type.

      So for example:

      m_skybox SkyboxInstance ;

      SkyboxInstance.Initialise( 10.0 ) ;

      Of course this begs the question of why you would not do the initialisation in a constructor so you could simply write:

      m_skybox SkyboxInstance( 10.0 ) ;

      Now this also highlights why your naming convention is so flawed, it even confused you, and since you are asking others to help, it will confuse them. It is named like a data member but is in fact a data type. So of course renaming it alone won't solve your problem - I never claimed it would - but flouting convention is seldom a good idea, especially whan you don't understand the convention or why it exists in the first place!

      What did you intend the m_ prefix to mean!? I am guessing that you 'copied' it from somewhare else without understanding what it was for, and then subsequently misused it.

      Clifford

       
    • starcreek

      starcreek - 2008-02-28

      ok, i threw in void Skybox in the CGfxOpenGL.h

      which makes varaibles such as Initialize(); to be declared.
      idk how to declare them :(

      What puzzles me is that i deleted void Render(); from what was already provided and i see that it is undeclared. so i added Init() but i got the same result of needing a declaration. Although if i keep the void Render();
      it says in the error log that 'it is not a type'

      Error Log:

      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: In member function void CGfxOpenGL::Render()': CGfxOpenGL.cpp:164: error:Render' is not a type
      CGfxOpenGL.cpp:164: error: request for member of non-aggregate type before '(' token

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

      Execution terminated

       
    • starcreek

      starcreek - 2008-02-28

      i was able to change the CGfxOpenGL.h file to where it read:
      class Skybox;

      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;
      };

      that fixed the problem with Render(); not having a type.
      although i am still left with the problem of Init() still needing to be defined-somehow in the CGfxOpenGL.h

       
    • BiT

      BiT - 2008-02-28

      Starcreek,
      You are missing the point here. OpenGL application are to complex if you dont understand the C++ language. You are having problems with simple C++ basics such as classes. Why are you so insistant on trying to make this work without knowing all the things you need to know? Why do you appear to be completely ignorant of responses back to you pointing out that you NEED MORE KNOWLEDGE. What the hell are you trying to accomplish that you can not take a little bit of time and study up on programming basics? It will only help you to do this. If you can not do that then quit wasting peoples time because you are not going to understand the answer you get anyways. Which means you will post again like you are doing here...ignoring what you have already been told and pissing off your help.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.