xref: /haiku/src/apps/haiku3d/texture/BitmapTexture.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 <opengl/GL/gl.h>
14 #include <opengl/GL/glu.h>
15 #include <stdio.h>
16 
17 
18 BitmapTexture::BitmapTexture(BBitmap* bitmap)
19 	:
20 	Texture()
21 {
22 	_Load(bitmap);
23 }
24 
25 
26 BitmapTexture::~BitmapTexture()
27 {
28 }
29 
30 
31 void
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, 4,
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 (%li, %li, %libits)\n",
47     	fId, (int32) bitmap->Bounds().Width(),
48     	(int32) bitmap->Bounds().Height(),
49     	8 * bitmap->BytesPerRow() / (int)bitmap->Bounds().Width());
50 
51 	delete bitmap;
52 }
53