I've recently started a game engine project using SDL,fmod and opengl..
I have a small problem with an accessor function that's supposed to return an SDL_Surface*...
But when I compile, it says an lvalue is required as left hand of operand..
This is my code:
OG.h (All classes should include this header..)
/*********************************************************************************************************************** ** OG.h created by Louis Fry 04/08/09 ** ** ** ***********************************************************************************************************************/ #ifndef __OG_BASE_H__ #define __OG_BASE_H__ //#include ".h" //#include ".h" // Sound manipulation library #include <fmod.h> //#include <fmod.hpp> // Graphics library #ifdef __APPLE__ # include <GLUT/glut.h> #else # include <GL/glut.h> #endif // Window management library #include <SDL/SDL.h> #include <SDL/SDL_opengl.h> // usefull headers #include <cmath> #include <vector> #include <string> #include <cstdlib> #include <unistd.h> #include <iostream> #include <cstdio> // OG specific Headers #include "OGTypes.h" #include "OGEngine.h" #endif
This is the types file:
OGTypes.h
#ifndef __OG_TYPES_H__ #define __OG_TYPES_H__ typedef char OGchar; typedef char* OGcstring; typedef int OGint; typedef short OGshort; typedef double OGdouble; typedef long OGlong; typedef float OGfloat; typedef bool OGbool; typedef void* OGpointer; typedef unsigned char OGuchar; typedef unsigned int OGuint; typedef unsigned short OGushort; typedef unsigned long OGulong; // Optionally typedef long int OGlint; typedef unsigned long int OGulint; typedef long long int OGint64; typedef unsigned long long int OGuint64; #endif
This defines the engine class OGEngine.h
#ifndef __OG_ENGINE_H__ #define __OG_ENGINE_H__ #include "OGTypes.h" struct OGEngine { /* Pointer to this structure */ static OGEngine* engine; // engine->status()...; /* Set graphics resolution */ OGuint w_res; OGuint h_res; /* Set graphics depth */ OGuint depth; /* Set flags to pass to sdl video mode */ OGuint flags; /* Surface the graphics lay on */ SDL_Surface * OG_Main_Frame; /* Default Constructor */ OGEngine(OGuint,OGuint,OGuint,SDL_Surface *); /* Destructor set to virtual to enable use anywhere in derived class(OGsystem) */ virtual ~OGEngine(); // ACCESSORS inline OGEngine* OGeng_get_engine(){ return engine; }; inline SDL_Surface * OGeng_get_window_surface(){ return OG_Main_Frame; }; inline OGuint OGeng_get_width_res(){ return w_res; }; inline OGuint OGeng_get_height_res(){ return h_res; }; inline OGuint OGeng_get_pixel_depth(){ return depth; }; inline OGuint OGeng_set_flags(OGuint f1,OGuint f2){ flags = f1; flags |= f2; return flags; }; // END ACCESSORS /* Initialize the engine (window with sdl set with opengl attributes) */ static void OGInit(); /* Create the OpenGL context and setup the viewport ** ** All drawing functions will be using opengl. */ static void OGInitDisplay(); /* Quit the gl context and application */ static void OGQuit(); }; #endif /*__OG_ENGINE_H__*/
This is OGEngine.cpp:
#include "OG.h" /* Default constructor */ OGEngine::OGEngine(OGuint w,OGuint h,OGuint d,SDL_Surface * surface) { w_res = w, h_res = h, depth = d, OG_Main_Frame = surface; } /* Destructor */ OGEngine::~OGEngine() { w_res = 0, h_res = 0, depth = 0; } /* Initialise sdl video mode with Opengl attributes */ void OGEngine::OGInit() { // Start sdl with complete opengl settings if(SDL_Init(SDL_INIT_VIDEO) != 0) { printf("\nSDL Init failed on error: %s",SDL_GetError()); return; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); } /* Setup an Opengl rendering context on sdl surface */ void OGEngine::OGInitDisplay() { /* Create the window with engine's properties */ engine->OGeng_get_window_surface() = SDL_SetVideoMode( engine->OGeng_get_width_res(), engine->OGeng_get_height_res(), engine->OGeng_get_pixel_depth(), engine->OGeng_set_flags(SDL_OPENGL,SDL_FULLSCREEN) ); } /* Quit opengl and sdl */ void OGEngine::OGQuit() { //if(OG_Main_Frame) SDL_FreeSurface(OG_Main_Frame); //~OGEngine(); SDL_Quit(); }
And finnaly this is the test program:
#include "OG.h" int main() { SDL_Surface * screen; OGEngine new_engine(1024,768,32,screen); OGEngine::OGInit(); OGEngine::OGInitDisplay(); return 0; }
I am using gPlusPlus in Linux Debian Lenny
This is my command:
gPlusPlus -o t OGEngine.cpp OGtest.cpp `sdl-config --libs --cflags`
and this is the error:
OGEngine.cpp: In static member function ‘static void OGEngine::OGInitDisplay()’:
OGEngine.cpp:65: error: lvalue required as left operand of assignment
This line seems to not be returning anything
engine->OGeng_get_window_surface()
Can anyone tell me wassup with this?? Could it be my usage of SDL??