Languages

Menu
Sites
Language
Loading textures

Hello. How to correctly load textures (OpenGL) ?  The textures are distorted and in different colour.

Image *obraz = new Image();
    Bitmap *graf1 = new Bitmap();

    obraz->Construct();
    graf1 = obraz->DecodeN(Tizen::App::App::GetInstance()->GetAppRootPath() + L"res/fire.png",BITMAP_PIXEL_FORMAT_R8G8B8A8);
    glGenTextures(1, &tex[0]);

glBindTexture(GL_TEXTURE_2D, tex[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  graf1->GetWidth(), graf1->GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE , graf1 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

Can someone show me the correct way (sample of code or something)

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

1 Replies
muditha murthy
My loadtexture function looks like this
Image image;
	String filepath = App::GetInstance()->GetAppResourcePath() + resFile;

	image.Construct();
	Bitmap *bitmap = image.DecodeN(filepath, BITMAP_PIXEL_FORMAT_R8G8B8A8);

	BufferInfo info;
	bitmap->Lock(info);
	GLuint* pBitmapBuffer = (GLuint*)info.pPixels;

	m_Sprite[id]._width = info.width;
	m_Sprite[id]._height = info.height;

	glGenTextures(1, &m_Sprite[id]._texture);
	glBindTexture(GL_TEXTURE_2D, m_Sprite[id]._texture);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)(info.width), (GLsizei)(info.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, pBitmapBuffer);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	bitmap->Unlock();

	delete bitmap;