1
2 #include "Global.h"
3
4
InitOpenGL(void)5 void InitOpenGL( void )
6 {
7
8
9
10
11 // viewport should cover the whole screen
12 glViewport( 0, 0, GL_Width, GL_Height );
13
14 // Camera projection matrix
15 glMatrixMode( GL_PROJECTION );
16 glLoadIdentity();
17 // Set Up An Ortho Screen
18 glOrtho( 0, (double)GL_Width, (double)GL_Height, 0, -100, 100 );
19
20
21 glLoadIdentity();
22 // Smooth Shading
23 glShadeModel( GL_SMOOTH );
24 // Line Smoothing
25 glEnable( GL_LINE_SMOOTH );
26 glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
27
28 // clear color
29
30 // Depth Buffer Setup
31 //glClearDepth( 1.0 );
32
33 glEnable( GL_BLEND );
34 // Blending function
35
36 // Alpha
37 //glEnable( GL_ALPHA_TEST );
38 // Alpha function
39 //glAlphaFunc( GL_GREATER, 0.1f );
40 // Perspective Calculations
41 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
42 // back-facing polygons
43 glDisable( GL_CULL_FACE );
44
45
46 }
47
48
49
50
51
52
Get_GLsize(unsigned int size)53 unsigned int Get_GLsize( unsigned int size )
54 {
55 unsigned int value = 1;
56
57 while( value < size )
58 {
59 value <<= 1;
60 }
61
62 return value;
63 }
64
drawGLscreen()65 void drawGLscreen()
66 {
67 #ifdef Use_OPENGL
68
69 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
70 glLoadIdentity();
71
72
73 unsigned int image_num = 0;
74 unsigned int width = Get_GLsize( screen->w );
75 unsigned int height = Get_GLsize( screen->h );
76
77
78
79
80 // create one texture
81 glGenTextures( 1, &image_num );
82 // use the generated texture
83 glBindTexture( GL_TEXTURE_2D, image_num );
84 // affect how this texture is drawn later on
85 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
86 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
87 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
88 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
89
90
91
92 // copies the sdl surface into the opengl texture
93 glPixelStorei( GL_UNPACK_ROW_LENGTH, screen->pitch / screen->format->BytesPerPixel );
94 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, screen->w, screen->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, screen->pixels );
95 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
96
97
98
99 glEnable( GL_TEXTURE_2D );
100 // texture id
101 glBindTexture( GL_TEXTURE_2D, image_num );
102
103 glScaled(0.003f,-0.004f,0);
104
105
106 // rectangle
107 glBegin( GL_QUADS );
108 // top left
109 glTexCoord2f( 0, 0 );
110 glVertex3d( -(int)width / 2, -(int)height / 2, 0 );
111 // top right
112 glTexCoord2f( 1, 0 );
113 glVertex3d( width / 2, -(int)height / 2, 0 );
114 // bottom right
115 glTexCoord2f( 1, 1 );
116 glVertex3d( width / 2, height / 2, 0 );
117 // bottom left
118 glTexCoord2f( 0, 1 );
119 glVertex3d( -(int)width / 2, height / 2, 0 );
120 glEnd();
121
122 glDisable( GL_TEXTURE_2D );
123 SDL_GL_SwapBuffers();
124
125 glDeleteTextures(1,&image_num );
126
127 #else
128
129 SDL_Flip(screen);
130
131 #endif
132
133 }
134