Browse Source

GLSDLScreen Funktioniert

Testprog ist ein Testprogramm, erstellt ein Fenster
seba 12 years ago
parent
commit
ef309c3240
7 changed files with 184 additions and 10 deletions
  1. 10
    6
      Makefile
  2. 3
    3
      glgui/Makefile
  3. 1
    1
      glgui/button.h
  4. 119
    0
      glsdlscreen.cpp
  5. 39
    0
      glsdlscreen.h
  6. 12
    0
      testprog.cpp
  7. 0
    0
      testprog.h

+ 10
- 6
Makefile View File

@@ -1,14 +1,15 @@
1 1
 COMPILER = g++
2
-OBJECTS = emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glgui/glgui.a
2
+OBJECTS = emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o glgui/glgui.a
3 3
 VERSION = 0.0.1
4
-LIBNAME = segl
4
+LIBNAME = libsegl
5 5
 
6 6
 
7
-sgllib: $(OBJECTS)
7
+segllib: $(OBJECTS)
8 8
 
9
-sglar: $(OBJECTS)
10
-	rm -f lib$(LIBNAME).a
11
-	ar rfc lib$(LIBNAME).a $(OBJECTS)
9
+seglar: $(OBJECTS)
10
+	rm -f $(LIBNAME).a
11
+	ar rcs $(LIBNAME).a $(OBJECTS)
12
+# 	ranlib $(LIBNAME).a
12 13
 	
13 14
 %.o: %.cpp %.h
14 15
 	$(COMPILER) -c `sdl-config --cflags` $<
@@ -17,6 +18,9 @@ sglar: $(OBJECTS)
17 18
 glgui/glgui.a:
18 19
 	cd glgui; $(MAKE);
19 20
 	
21
+testprog: seglar testprog.o
22
+	g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a 
23
+	
20 24
 clean:
21 25
 	rm -f $(OBJECTS)
22 26
 	cd glgui; $(MAKE) clean

+ 3
- 3
glgui/Makefile View File

@@ -1,9 +1,9 @@
1
-# COMPILER = g++
1
+COMPILER = g++
2 2
 OBJECTS = button.o object.o textlabel.o window.o
3 3
 
4 4
 glguilib: $(OBJECTS)
5
-	rm glgui.a -f
6
-	ar rfc glgui.a $(OBJECTS)
5
+# 	rm glgui.a -f
6
+	ar crus glgui.a $(OBJECTS)
7 7
 
8 8
 %.o: %.cpp %.h
9 9
 	$(COMPILER) -c `sdl-config --cflags` $<

+ 1
- 1
glgui/button.h View File

@@ -22,7 +22,7 @@ class GLGuiButton : public GLGuiTextLabel {
22 22
 		void setHighlightColor();
23 23
 		
24 24
 		void onMouseOver(int m_x, int m_y);
25
-		void onMouseClick(int m_x, int m_y);
25
+		void onMouseClick(int m_x, int m_y, int m_button);
26 26
 };
27 27
 
28 28
 #endif

+ 119
- 0
glsdlscreen.cpp View File

@@ -0,0 +1,119 @@
1
+#include "glsdlscreen.h"
2
+
3
+GLSDLScreen::GLSDLScreen() {
4
+	width = 0;
5
+	height = 1;
6
+	bpp = 16;
7
+	znear = 1.0f;
8
+	zfar = 100.0f;
9
+	
10
+	opengl = false;
11
+	glsetup = true;
12
+	resizable = false;
13
+	fullscreen = false;
14
+	
15
+	extraglparam = 0;
16
+}
17
+
18
+
19
+int GLSDLScreen::getFlags() {
20
+	const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
21
+	int videoflags = 0;
22
+	if(videoInfo->hw_available)
23
+		videoflags |= SDL_HWSURFACE;
24
+	else
25
+		videoflags |= SDL_SWSURFACE;
26
+	if(videoInfo->blit_hw)
27
+		videoflags |= SDL_HWACCEL;
28
+	
29
+	if(opengl) {
30
+		videoflags |= SDL_OPENGL;
31
+		videoflags |= SDL_GL_DOUBLEBUFFER;
32
+		videoflags |= SDL_HWPALETTE;
33
+	}
34
+	
35
+	return videoflags;
36
+}
37
+void GLSDLScreen::enableOpenGL(bool w) {
38
+	opengl = w;
39
+}
40
+
41
+void GLSDLScreen::enableResizable(bool w) {
42
+	resizable = w;
43
+}
44
+
45
+void GLSDLScreen::enableFullscreen(bool w) {
46
+	fullscreen = w;
47
+}
48
+
49
+void GLSDLScreen::setGLNearFar(float _znear, float _zfar) {
50
+	znear = _znear;
51
+	zfar  = _zfar;
52
+}
53
+
54
+void GLSDLScreen::enableGLSetup(bool w) {
55
+	glsetup = w;
56
+}
57
+
58
+void GLSDLScreen::setExtraGLParamFunc(void (*extrafunc)()) {
59
+	extraglparam = extrafunc;
60
+}
61
+
62
+void GLSDLScreen::setVideoMode(int _width, int _height, int _bpp) {
63
+	width = _width;
64
+	height = _height;
65
+	bpp = _bpp;
66
+	
67
+	if(height==0)
68
+		height = 1;
69
+}
70
+
71
+bool GLSDLScreen::isOK() {
72
+	return SDL_VideoModeOK(width, height, bpp, getFlags());
73
+}
74
+
75
+bool GLSDLScreen::apply() {
76
+	if(!SDL_WasInit(SDL_INIT_VIDEO)) {
77
+		if(SDL_Init(SDL_INIT_VIDEO)==-1) {
78
+			return false;
79
+		}
80
+	}
81
+
82
+	screen = SDL_SetVideoMode(width, height, bpp, getFlags());
83
+	
84
+	if(!screen) {
85
+		return false;
86
+	}
87
+	
88
+	if(opengl) {
89
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
90
+			
91
+		
92
+		// Setup GL
93
+		if(glsetup) {
94
+			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
95
+			glClearDepth(1.0f);
96
+			glDepthFunc(GL_LEQUAL);
97
+			glShadeModel(GL_SMOOTH);
98
+			glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
99
+			glEnable(GL_ALPHA_TEST);
100
+			glAlphaFunc(GL_GREATER, 0.1);
101
+		}
102
+		
103
+		// Projection
104
+		glViewport(0, 0, (GLsizei)width, (GLsizei)height);
105
+		
106
+		glMatrixMode(GL_PROJECTION);
107
+		glLoadIdentity();
108
+		gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, znear, zfar);
109
+		
110
+		if(extraglparam) {
111
+			extraglparam();
112
+		}
113
+		
114
+		// Texturen neuladen, eigentlich nur für Windows. Aber egal.
115
+		GLTexture::reloadAll();
116
+	}
117
+	
118
+	return true;
119
+}

+ 39
- 0
glsdlscreen.h View File

@@ -0,0 +1,39 @@
1
+#ifndef __GLSDLSCREEN_H
2
+#define __GLSDLSCREEN_H
3
+
4
+#include <iostream>
5
+#include <SDL.h>
6
+#include <SDL_opengl.h>
7
+#include "gltexture.h"
8
+
9
+class GLSDLScreen {
10
+	private:
11
+		SDL_Surface *screen;
12
+		
13
+		int width, height, bpp;
14
+		bool opengl;
15
+		bool glsetup;
16
+		bool resizable;
17
+		bool fullscreen;
18
+		
19
+		// OpenGL related
20
+		float znear, zfar;
21
+		void (*extraglparam)();
22
+		int getFlags();
23
+	public:
24
+		GLSDLScreen();
25
+		
26
+		void enableOpenGL(bool);
27
+		void enableResizable(bool);
28
+		void enableFullscreen(bool);
29
+		void setVideoMode(int _width, int _height, int _bpp);
30
+		
31
+		void setGLNearFar(float _znear, float _zfar);
32
+		void enableGLSetup(bool);
33
+		void setExtraGLParamFunc(void (*extrafunc)());
34
+		
35
+		bool isOK();
36
+		bool apply();
37
+};
38
+
39
+#endif

+ 12
- 0
testprog.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+#include "glsdlscreen.h"
3
+
4
+int main() {
5
+	GLSDLScreen screen;
6
+
7
+	screen.enableOpenGL(true);
8
+	screen.setVideoMode(640, 480, 32);
9
+	screen.apply();
10
+
11
+	return 0;
12
+}

+ 0
- 0
testprog.h View File


Loading…
Cancel
Save