1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
* Copyright © 2009 Kristian Høgsberg
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <math.h>
#include <GL/gl.h>
#include <poll.h>
#include <fcntl.h>
#include <unistd.h>
#include "../eagle.h"
#include "setup.h"
static int init(struct state *state)
{
return 0;
}
static int render(struct state *state)
{
GLfloat vertices[12];
GLfloat tex_coords[8] = { 1, 0, 1, 1, 0, 1, 0, 0 };
GLuint indices[4] = { 0, 1, 2, 3 };
uint32_t texture[128 * 128];
GLuint colors[] = {
0x00000000, 0x00110000, 0x00001100, 0x00000011,
0x00001111, 0x00110011, 0x00111100, 0x00111111
};
int i, row, column;
for (i = 0; i < 128 * 128; i++) {
row = (i >> 11) & 0x07;
column = ((i >> 3) & 0x0e) + 1;
texture[i] = colors[row] * column;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 128);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texture);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glViewport(0, 0, state->width, state->height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glClearColor(0, 0.1, 0.1, 0.1);
glClear(GL_COLOR_BUFFER_BIT);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_BLEND);
vertices[0] = 0.9;
vertices[1] = -0.9;
vertices[2] = 0;
vertices[3] = 0.9;
vertices[4] = 0.9;
vertices[5] = 0;
vertices[6] = -0.9;
vertices[7] = 0.9;
vertices[8] = 0;
vertices[9] = -0.9;
vertices[10] = -0.9;
vertices[11] = 0;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, tex_coords);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, indices);
glFlush();
eglSwapBuffers(state->display, state->surface);
getchar();
return 0;
}
int main(int argc, char *argv[])
{
return setup(argc, argv, init, render);
}
|