graphics

experiments with opengl3.2/ogles3.3 on linux and win7
git clone http://frotz.net/git/graphics.git
Log | Files | Refs

app.h (1793B)


      1 /* Copyright 2013 Brian Swetland <swetland@frotz.net>
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *     http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  */
     15 
     16 #ifndef _APP_H_
     17 #define _APP_H_
     18 
     19 #include "core.h"
     20 
     21 class App {
     22 public:
     23 	App();
     24 	virtual ~App();
     25 	void fullscreen(int yes);
     26 
     27 	virtual int init(void) = 0;
     28 	virtual void render(void) = 0;
     29 	virtual void release(void) {};
     30 	virtual void onKeyDown(unsigned code) {};
     31 	virtual void onKeyUp(unsigned code) {};
     32 	virtual void onResize(void) {};
     33 
     34 	int getWidth(void) { return width; }
     35 	int getHeight(void) { return height; }
     36 	int isFullscreen(void) { return _fullscreen; }
     37 	int keydown(unsigned code) {
     38 		return keystate[code >> 5] & (1 << (code & 0x1f));
     39 	}
     40 
     41 	static int __main(int argc, char **argv);
     42 
     43 protected:
     44 	int width;
     45 	int height;
     46 
     47 	/* mouse motion since last frame */
     48 	int mouseDX, mouseDY, mouseDZ;
     49 	/* mouse button state */
     50 	int mouseBTN;
     51 	/* mouse position in window coordinates */
     52 	int mouseWX, mouseWY;
     53 
     54 	/* keys down */
     55 	unsigned keystate[16];
     56 	int fps;
     57 
     58 private:
     59 	int start(void);
     60 	void handleEvents(void);
     61 	void setOptions(int argc, char **argv);
     62 
     63 	int _vsync;
     64 	int _fullscreen;
     65 	SDL_Window *win;
     66 	SDL_GLContext glcontext;
     67 };
     68 
     69 App *createApp(void);
     70 
     71 void printx(const char *fmt, ...);
     72 void printmtx(float *m, const char *name);
     73 int error(const char *fmt, ...);
     74 
     75 #endif