repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haiku3d / texture / BitmapTexture.cpp
blob483daadfb5ae4e737e4acfeddaf9656762b4755e
1 /*
2 * Copyright 2009, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Alexandre Deckner <alex@zappotek.com>
7 */
9 #include "BitmapTexture.h"
11 #include <Bitmap.h>
13 #include <GL/gl.h>
14 #include <GL/glu.h>
15 #include <stdio.h>
18 BitmapTexture::BitmapTexture(BBitmap* bitmap)
20 Texture()
22 _Load(bitmap);
26 BitmapTexture::~BitmapTexture()
31 void
32 BitmapTexture::_Load(BBitmap* bitmap) {
33 if (bitmap == NULL)
34 return;
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());
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());
52 delete bitmap;