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

« back to all changes in this revision

Viewing changes to tests/sdl_ogl_defaultMatrixMode.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:
46
46
        printf("Unable to set video mode: %s\n", SDL_GetError());
47
47
        return 1;
48
48
    }
49
 
    
 
49
 
50
50
    // Set the OpenGL state after creating the context with SDL_SetVideoMode
51
51
 
52
52
    glClearColor( 0, 0, 0, 0 );
53
 
    
54
 
#if !EMSCRIPTEN
55
 
    glEnable( GL_TEXTURE_2D ); // Need this to display a texture XXX unnecessary in OpenGL ES 2.0/WebGL
56
 
#endif
 
53
 
 
54
    glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline.
57
55
 
58
56
    glViewport( 0, 0, 640, 480 );
59
57
 
66
64
    glLoadIdentity();
67
65
 
68
66
    glOrtho( 0, 640, 480, 0, -1, 1 );
69
 
    
 
67
 
70
68
    // Load the OpenGL texture
71
69
 
72
70
    GLuint texture; // Texture object handle
73
71
    SDL_Surface *surface; // Gives us the information to make the texture
74
 
    
75
 
    if ( (surface = IMG_Load("screenshot.png")) ) { 
76
 
    
 
72
 
 
73
    if ( (surface = IMG_Load("screenshot.png")) ) {
 
74
 
77
75
        // Check that the image's width is a power of 2
78
76
        if ( (surface->w & (surface->w - 1)) != 0 ) {
79
77
            printf("warning: image.bmp's width is not a power of 2\n");
80
78
        }
81
 
    
 
79
 
82
80
        // Also check if the height is a power of 2
83
81
        if ( (surface->h & (surface->h - 1)) != 0 ) {
84
82
            printf("warning: image.bmp's height is not a power of 2\n");
85
83
        }
86
 
    
 
84
 
87
85
        // Have OpenGL generate a texture object handle for us
88
86
        glGenTextures( 1, &texture );
89
 
    
 
87
 
90
88
        // Bind the texture object
91
89
        glBindTexture( GL_TEXTURE_2D, texture );
92
 
        
 
90
 
93
91
        // Set the texture's stretching properties
94
92
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
95
93
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
100
98
        memset(surface->pixels, 0x66, surface->w*surface->h);
101
99
 
102
100
        // Edit the texture object's image data using the information SDL_Surface gives us
103
 
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, 
 
101
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
104
102
                      GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
105
103
 
106
104
        //SDL_UnlockSurface(surface);
107
 
    } 
 
105
    }
108
106
    else {
109
107
        printf("SDL could not load image.bmp: %s\n", SDL_GetError());
110
108
        SDL_Quit();
111
109
        return 1;
112
 
    }    
113
 
    
 
110
    }
 
111
 
114
112
    // Free the SDL_Surface only if it was successfully created
115
 
    if ( surface ) { 
 
113
    if ( surface ) {
116
114
        SDL_FreeSurface( surface );
117
115
    }
118
 
    
 
116
 
119
117
    // Clear the screen before drawing
120
118
    glClear( GL_COLOR_BUFFER_BIT );
121
 
    
 
119
 
122
120
    // Bind the texture to which subsequent calls refer to
123
121
    glBindTexture( GL_TEXTURE_2D, texture );
124
122
 
141
139
        glTexCoord2i( 0, 1 ); glVertex3f( 500, 410, 0 );
142
140
    glEnd();
143
141
 
144
 
#if !EMSCRIPTEN
145
142
    glDisable(GL_TEXTURE_2D);
146
 
#endif
147
143
 
148
144
    glColor3ub(90, 255, 255);
149
145
    glBegin( GL_QUADS );
161
157
    glEnd();
162
158
 
163
159
    SDL_GL_SwapBuffers();
164
 
    
 
160
 
165
161
#if !EMSCRIPTEN
166
162
    // Wait for 3 seconds to give us a chance to see the image
167
163
    SDL_Delay(3000);
169
165
 
170
166
    // Now we can delete the OpenGL texture and close down SDL
171
167
    glDeleteTextures( 1, &texture );
172
 
    
 
168
 
173
169
    SDL_Quit();
174
 
    
 
170
 
175
171
    return 0;
176
172
}