Jump to content

Recommended Posts

Posted

I took this example from the documentation for SetPixel, i commented out Texture::Create and replaced it with Texture::Load but it crashes when doing memcpys but it doesn't if i don't load a texture and use Create instead. The texture loads fine, i'm able to display it.

 

Error:

HEAP[Test.debug.exe]: Heap block at 0655D900 modified at 0656192C past requested size of 4024

Test.debug.exe has triggered a breakpoint.

 

 

 

In App::Start


//texture = Texture::Create(256, 256);

texture = Texture::Load("mytexture.tex"); // texture is defined in App.h

//Create a buffer to store pixel data in
int datasize = texture->GetMipmapSize(0);
char* pixels = (char*)malloc(datasize);

//Get the pixel data from the texture and invert it
texture->GetPixels(pixels);
char r, g, b, a;
for (int x = 0; x<texture->GetWidth(); x++)
{
 for (int y = 0; y<texture->GetHeight(); y++)
 {
	 int p = (x*texture->GetWidth() + y) * 4;
	 memcpy(&r, pixels + p + 0, 1);
	 memcpy(&g, pixels + p + 1, 1);
	 memcpy(&b, pixels + p + 2, 1);

	 r = 255 - r;
	 g = 255 - g;
	 b = 255 - b;

	 memcpy(pixels + p + 0, &r, 1);
	 memcpy(pixels + p + 1, &g, 1);
	 memcpy(pixels + p + 2, &b, 1);
 }
}

//Set the modified pixel data
texture->SetPixels(pixels);
free(pixels);

[c++] SetPixel/memcpy crash

Posted

The loaded texture is probably a different format.

It's an uncompressed RGBA texture 128x32, MipMaps:8.

 

I'm trying to create a render target (buffer) and draw on it. Then i later found i could just texture->draw on a created buffer. The only problem i'm facing now is that if i try to draw another image with alpha over the first one, it draws it opaque. I did try glEnable(GL_BLEND) but it didn't work.

 

 

 m_buffer->Enable();
m_buffer->SetColor(m_background_color);
m_buffer->Clear();
m_buffer->SetColor(1, 1, 1, 1);

// first one draws fine
 m_texture_elements[0]->texture->Draw(0, 0, m_texture_elements[0]->texture->width, m_texture_elements[0]->texture->height);

// not applying alpha over first one
 m_texture_elements[0]->texture->Draw(60, 0, m_texture_elements[0]->texture->width, m_texture_elements[0]->texture->height);

post-14340-0-33280900-1429548739.png

Posted

I solved the alpha issue using this:

 

	 	 m_texture_elements[0]->texture->Draw(0, 0, m_texture_elements[0]->texture->width, m_texture_elements[0]->texture->height);


		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		m_texture_elements[0]->texture->Draw(50, 0, m_texture_elements[0]->texture->width, m_texture_elements[0]->texture->height);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		m_texture_elements[0]->texture->Draw(80, 0, m_texture_elements[0]->texture->width, m_texture_elements[0]->texture->height);

 

Every time i draw sequentially on the same buffer, i have to enable GL_BLEND and set blend flags, is it normal?

post-14340-0-66909500-1429552843.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...