blob: 214291b3b156a3c3cbb8a69e56a057d994830207 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <stdlib.h>
19#include <stdio.h>
20
21#include <EGL/egl.h>
22#include <GLES/gl.h>
23#include <GLES/glext.h>
24
25int main(int argc, char** argv)
26{
27 EGLint s_configAttribs[] = {
28 EGL_RED_SIZE, 5,
29 EGL_GREEN_SIZE, 6,
30 EGL_BLUE_SIZE, 5,
31 EGL_NONE
32 };
33
34 EGLint numConfigs = -1;
35 EGLint majorVersion;
36 EGLint minorVersion;
37 EGLConfig config;
38 EGLContext context;
39 EGLSurface surface;
40 EGLint w, h;
41
42 EGLDisplay dpy;
43
44 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
45 eglInitialize(dpy, &majorVersion, &minorVersion);
46 eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs);
47 surface = eglCreateWindowSurface(dpy, config,
48 android_createDisplaySurface(), NULL);
49 context = eglCreateContext(dpy, config, NULL, NULL);
50 eglMakeCurrent(dpy, surface, surface, context);
51 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
52 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
53 GLint dim = w<h ? w : h;
54
55
56 GLint crop[4] = { 0, 4, 4, -4 };
57 glBindTexture(GL_TEXTURE_2D, 0);
58 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
59 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
60 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
61 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
62 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
64 glEnable(GL_TEXTURE_2D);
65 glColor4f(1,1,1,1);
66
67 // packing is always 4
68 uint8_t t8[] = {
69 0x00, 0x55, 0x00, 0x55,
70 0xAA, 0xFF, 0xAA, 0xFF,
71 0x00, 0x55, 0x00, 0x55,
72 0xAA, 0xFF, 0xAA, 0xFF };
73
74 uint16_t t16[] = {
75 0x0000, 0x5555, 0x0000, 0x5555,
76 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF,
77 0x0000, 0x5555, 0x0000, 0x5555,
78 0xAAAA, 0xFFFF, 0xAAAA, 0xFFFF };
79
80 uint16_t t5551[] = {
81 0x0000, 0xFFFF, 0x0000, 0xFFFF,
82 0xFFFF, 0x0000, 0xFFFF, 0x0000,
83 0x0000, 0xFFFF, 0x0000, 0xFFFF,
84 0xFFFF, 0x0000, 0xFFFF, 0x0000 };
85
86 uint32_t t32[] = {
87 0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFFFF0000,
88 0xFF00FF00, 0xFFFF0000, 0xFF000000, 0xFF0000FF,
89 0xFF00FFFF, 0xFF00FF00, 0x00FF00FF, 0xFFFFFF00,
90 0xFF000000, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF
91 };
92
93
94 glClear(GL_COLOR_BUFFER_BIT);
95 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, t8);
96 glDrawTexiOES(0, 0, 0, dim/2, dim/2);
97
98 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, t16);
99 glDrawTexiOES(dim/2, 0, 0, dim/2, dim/2);
100
101 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, t16);
102 glDrawTexiOES(0, dim/2, 0, dim/2, dim/2);
103
104 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
105 glDrawTexiOES(dim/2, dim/2, 0, dim/2, dim/2);
106
107 eglSwapBuffers(dpy, surface);
108 return 0;
109}