1 /*
2 * Copyright 2009, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Alexandre Deckner <alex@zappotek.com>
7 */
8
9 #include "BitmapTexture.h"
10
11 #include <Bitmap.h>
12
13 #include <GL/gl.h>
14 #include <GL/glu.h>
15 #include <stdio.h>
16
17
BitmapTexture(BBitmap * bitmap)18 BitmapTexture::BitmapTexture(BBitmap* bitmap)
19 :
20 Texture()
21 {
22 _Load(bitmap);
23 }
24
25
~BitmapTexture()26 BitmapTexture::~BitmapTexture()
27 {
28 }
29
30
31 void
_Load(BBitmap * bitmap)32 BitmapTexture::_Load(BBitmap* bitmap) {
33 if (bitmap == NULL)
34 return;
35
36 glGenTextures(1, &fId);
37 glBindTexture(GL_TEXTURE_2D, fId);
38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
40 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
41 (int) bitmap->Bounds().Width() + 1,
42 (int) bitmap->Bounds().Height() + 1,
43 0, GL_BGRA, GL_UNSIGNED_BYTE,
44 bitmap->Bits());
45
46 printf("BitmapTexture::_Load, loaded texture %u "
47 "(%" B_PRIi32 ", %" B_PRIi32 ", %" B_PRIi32 "bits)\n",
48 fId, (int32) bitmap->Bounds().Width(),
49 (int32) bitmap->Bounds().Height(),
50 8 * bitmap->BytesPerRow() / (int)bitmap->Bounds().Width());
51
52 delete bitmap;
53 }
54