summaryrefslogtreecommitdiff
path: root/src/test.cc
blob: 5289762feb498925fdd5168ca59dc19a5fbc0a97 (plain)
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
#include <SDL.h>
#include <generic.h>
#include <Main.h>
#include <Input.h>
#include "glbase.h"
#include "gltexture.h"
#include "glfont.h"

CODE_BEGINS
virtual int startup() throw (GeneralException) {
    Uint8 * texture;
    verbosity = M_INFO;
    mogltk::glbase::setup();
    Input ffont("font.bin");
    mogltk::font font(&ffont);
    
    verbosity = M_INFO;
    
    mogltk::texture * mytex = new mogltk::texture(256, 256, true);
    
    texture = (Uint8 *) mytex->GetSurface()->pixels;
    
    for (int y = 0; y < 256; y++) {
	for (int x = 0; x < 256; x++) {
	    int r = random() % 256;
	    texture[(x + y * 256) * 4 + 0] = r;
	    texture[(x + y * 256) * 4 + 1] = r;
	    texture[(x + y * 256) * 4 + 2] = r;
	    texture[(x + y * 256) * 4 + 3] = 255;
	}
    }
    
    SDL_Surface * s;
    
    if (!(s = SDL_LoadBMP("pattern6.bmp"))) {
	throw GeneralException("Error: could not load texture.");
    }
    SDL_BlitSurface(s, NULL, mytex->GetSurface(), NULL);
    
/*
    for (int y = 0; y < 256; y += 2) {
	for (int x = 0; x < 256; x += 2) {
	    texture[(x + y * 256) * 4 + 0] = 0;
	    texture[(x + y * 256) * 4 + 1] = 0;
	    texture[(x + y * 256) * 4 + 2] = 255;
	    texture[(x + y * 256) * 4 + 3] = 0;
	}
    }
*/

    mogltk::glbase::Enter2DMode();
    
    mytex->Bind();
    glBegin(GL_TRIANGLE_STRIP);
    glColor3d(0, 0, 0);
    glTexCoord2i(0, 0);
    glVertex2f(50, 50);
    glColor3d(1, 0, 0);
    glTexCoord2i(511, 0);
    glVertex2f(561, 50);
    glColor3d(0, 1, 0);
    glTexCoord2i(0, 511);
    glVertex2f(50, 561);
    glColor3d(0, 0, 1);
    glTexCoord2i(511, 511);
    glVertex2f(561, 561);
    glEnd();
    
    mogltk::texture::Unbind();
    glBegin(GL_TRIANGLE_STRIP);
    glColor3d(0, 0, 0);
    glVertex2f(400, 100);
    glColor3d(1, 0, 0);
    glVertex2f(450, 100);
    glColor3d(0, 1, 0);
    glVertex2f(400, 150);
    glColor3d(0, 0, 1);
    glVertex2f(450, 150);
    glEnd();
    mogltk::glbase::Leave2DMode();
    
    font.putcursor(10, 10);
    font.setcolor(Color(255, 0, 0));
    font.printf("PixelPawa!");
    font.newline();
    font.printf("It works!!");
    font.newline();
    font.printf("I can't believe it!");
    
    mogltk::glbase::Flip();
    
//    sleep(15);
    getchar();
    
    delete mytex;
    
    return 0;
}
CODE_ENDS