~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/gl_ps.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-06-11 15:45:24 UTC
  • mfrom: (1.2.1) (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130611154524-rppb3w6tixlegv4n
Tags: 1.4.7~20130611~a1eb425-1
* New snapshot release
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
        printf("Unable to set video mode: %s\n", SDL_GetError());
116
116
        return 1;
117
117
    }
118
 
    
 
118
 
119
119
    // Set the OpenGL state after creating the context with SDL_SetVideoMode
120
120
 
121
121
    glClearColor( 0, 0, 0, 0 );
122
 
    
 
122
 
123
123
#if !EMSCRIPTEN
124
124
    glEnable( GL_TEXTURE_2D ); // Need this to display a texture XXX unnecessary in OpenGL ES 2.0/WebGL
125
125
#endif
135
135
 
136
136
    glMatrixMode( GL_MODELVIEW );
137
137
    glLoadIdentity();
138
 
    
 
138
 
139
139
    // Load the OpenGL texture
140
140
 
141
141
    GLuint texture; // Texture object handle
142
142
    SDL_Surface *surface; // Gives us the information to make the texture
143
 
    
144
 
    if ( (surface = IMG_Load("screenshot.png")) ) { 
145
 
    
 
143
 
 
144
    if ( (surface = IMG_Load("screenshot.png")) ) {
 
145
 
146
146
        // Check that the image's width is a power of 2
147
147
        if ( (surface->w & (surface->w - 1)) != 0 ) {
148
148
            printf("warning: image.bmp's width is not a power of 2\n");
149
149
        }
150
 
    
 
150
 
151
151
        // Also check if the height is a power of 2
152
152
        if ( (surface->h & (surface->h - 1)) != 0 ) {
153
153
            printf("warning: image.bmp's height is not a power of 2\n");
154
154
        }
155
 
    
 
155
 
156
156
        // Have OpenGL generate a texture object handle for us
157
157
        glGenTextures( 1, &texture );
158
 
    
 
158
 
159
159
        // Bind the texture object
160
160
        glBindTexture( GL_TEXTURE_2D, texture );
161
 
        
 
161
 
162
162
        // Set the texture's stretching properties
163
163
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
164
164
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
169
169
        memset(surface->pixels, 0x66, surface->w*surface->h);
170
170
 
171
171
        // Edit the texture object's image data using the information SDL_Surface gives us
172
 
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, 
 
172
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
173
173
                      GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
174
174
 
175
175
        //SDL_UnlockSurface(surface);
176
 
    } 
 
176
    }
177
177
    else {
178
178
        printf("SDL could not load image.bmp: %s\n", SDL_GetError());
179
179
        SDL_Quit();
180
180
        return 1;
181
 
    }    
182
 
    
 
181
    }
 
182
 
183
183
    // Free the SDL_Surface only if it was successfully created
184
 
    if ( surface ) { 
 
184
    if ( surface ) {
185
185
        SDL_FreeSurface( surface );
186
186
    }
187
 
    
 
187
 
188
188
    // Clear the screen before drawing
189
189
    glClear( GL_COLOR_BUFFER_BIT );
190
 
    
 
190
 
191
191
    shaders();
192
192
 
193
193
    // Bind the texture to which subsequent calls refer to
218
218
    glDisableClientState(GL_VERTEX_ARRAY);
219
219
 
220
220
    SDL_GL_SwapBuffers();
221
 
    
 
221
 
222
222
#if !EMSCRIPTEN
223
223
    // Wait for 3 seconds to give us a chance to see the image
224
224
    SDL_Delay(3000);
226
226
 
227
227
    // Now we can delete the OpenGL texture and close down SDL
228
228
    glDeleteTextures( 1, &texture );
229
 
    
 
229
 
230
230
    SDL_Quit();
231
 
    
 
231
 
232
232
    return 0;
233
233
}