Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Xenkan

Member Since 12 Nov 2010
Offline Last Active Dec 09 2011 05:30 PM

Posts I've Made

In Topic: VBO problem, first vertex in wrong position

30 November 2011 - 04:37 PM

I guess I feel that using a library to load a library seems superfluous. In retrospect, it obviously would have saved me some headache. I've got it working now, but if I need more than 4 functions in the future, I might use GLEW. Thanks for the tip!

In Topic: VBO problem, first vertex in wrong position

27 November 2011 - 09:09 AM

In case anyone searches this later, I finally solved my problem.

I'm loading my function pointers using wglGetProcAddress. However, the function pointers were not marked STDCALL. I believe this was causing my local variables, ie. stack-based variables, to become corrupted.

In other words, I was doing this:

void (*glBindBuffer)(int target, uint buffer);
glBindBuffer = (void (*)(int target, uint buffer))wglGetProcAddress("glBindBuffer");

I should've been doing this:

STDCALL void (*glBindBuffer)(int target, uint buffer);
glBindBuffer = (void (*)(int target, uint buffer))wglGetProcAddress("glBindBuffer");

Thanks Sponji, for tipping me off that Linux doesn't have wglGetProcAddress, and therefore doesn't have this problem!

In Topic: VBO problem, first vertex in wrong position

03 November 2011 - 06:58 AM

Hi Sponji, thank you very much for taking the time to test this! I'm glad I used SDL.

Well... maybe the problem has something to do with my build environment, or my testing PCs? I'm building on Windows XP using TDM GCC 4.5.1. The two PCs I tested the .exe on were both Windows XP. I tried testing on a third PC, but that PC didn't seem to support the buffer functions, so that was a: FAIL.

Some more information to add:

I've been playing around with gDEBugger, which seems like a great program so far! Here's what my VBO looks like in gDEBugger:

Posted Image

The x coordinate for my first vertex is NOT correct. It is listed as 1.0089349e-043 instead of -10.

In Topic: bitmap fun!

13 November 2010 - 03:08 AM

Hi Stu,

When I tested this code, I got slightly different results than you described. The code would segfault after finding a match. This is because the section which recognizes a complete match does not terminate the loop, and continues trying to compare pixels past the end of the smaller otherTexture subbitmap.

if(testPosition == otherTexture.textureInfo.biWidth * otherTexture.textureInfo.biHeight)
{
//found a whole match
counter++;
std::cout << "found: " << counter << "starting at pixel: " << s << "," << t << std::endl;
test = true; //found at least one
break; // <-- You should break the comparison loop here
}
or better yet, return true if you only care about finding one match.


Also, the following test is unnecessary and redundant:

if(s >= this->textureInfo.biHeight || t >= this->textureInfo.biWidth)
break;
because your for loop conditions are already testing this.


As a minor speed improvement, I suggest that you could move the "source texture not big enough" test up to immediately following the first pixel match. In other words, you could change this test:

if(s+ otherPosY >= this->textureInfo.biHeight || t+otherPosX>= this->textureInfo.biWidth)
break;
change it to:

if (s + otherTexture.textureInfo.biHeight > this->textureInfo.biHeight ||
t + otherTexture.textureInfo.biWidth > this->textureInfo.biWidth)
break;
And move it to immediately following the first pixel test:

if( this->dataVector[s][t].Matches(otherTexture.dataVector[0][0]) )
This way, the code doesn't bother attempting a full comparison if the source texture isn't large enough to find a match at those coordinates.


Lastly, it is my understanding that the bitmap spec allows top-to-bottom bitmaps, indicated with a negative biHeight. See http://msdn.microsoft.com/en-us/library/dd183376(v=VS.85).aspx The bottom-to-top bitmaps with a positive biHeight, which you have coded for, are much more common. But you may want to be careful, and check for this in your loading code:

GameTexture::textureData = LoadBitmapFile(filename, &(GameTexture::textureInfo));
if (textureInfo.biBitCount != 24 || // not 24 BPP
textureInfo.biCompression != BI_RGB || // compressed
textureInfo.biHeight < 0) // top-to-bottom
return false;


Here are the suggested changes all together:

GameTexture::Initialize(char * filename)
{
std::cout << "initializing!" << std::endl;
//load up the texture
GameTexture::textureData = LoadBitmapFile(filename, &(GameTexture::textureInfo));

if (textureInfo.biBitCount != 24 || // not 24 BPP
textureInfo.biCompression != BI_RGB || // compressed
textureInfo.biHeight < 0) // top-to-bottom
return false;

std::cout << "texture width: " << textureInfo.biWidth << std::endl;
std::cout << "texture height: " << textureInfo.biHeight << std::endl;
if(!textureData)
{
std::cout << "ERROR! " << std::endl;
return false;
}

//int counter = 0;
for(unsigned int s=0; s<this->textureInfo.biHeight;s++)
{
std::vector<PixelPart> newVec;
for(unsigned int t=0; t<this->textureInfo.biWidth; t++)
{
PixelPart p;
p.r = (int)this->textureData[(s*textureInfo.biWidth + t)*3];
p.g = (int)this->textureData[(s*textureInfo.biWidth + t)*3 + 1];
p.b = (int)this->textureData[(s*textureInfo.biWidth + t)*3 + 2];

newVec.push_back(p);
}
dataVector.push_back(newVec);
}

//other unnecessary code here
}



std::cout << "searching for other texture...\n";
if(otherTexture.textureInfo.biHeight > this->textureInfo.biHeight || otherTexture.textureInfo.biWidth > this->textureInfo.biWidth)
{
std::cout << "impossible to search for a texture that is bigger than this one." << std::endl;
return false;
}

bool test = false;
int counter = 0;
int highestMatch = 0;

for(unsigned int s=0; s< this->textureInfo.biHeight; s++)
{
for(unsigned int t=0; t< this->textureInfo.biWidth; t++)
{

if( this->dataVector[s][t].Matches(otherTexture.dataVector[0][0]) )
{
if (s + otherTexture.textureInfo.biHeight > this->textureInfo.biHeight ||
t + otherTexture.textureInfo.biWidth > this->textureInfo.biWidth)
break;

//std::cout << "found starting match: " << s << ", " << t << std::endl;
//loop through the rest of the other texture
int testPosition = 1;
int otherPosY = testPosition / otherTexture.textureInfo.biWidth;
int otherPosX = testPosition % otherTexture.textureInfo.biWidth;

if(s+ otherPosY >= this->textureInfo.biHeight || t+otherPosX >= this->textureInfo.biWidth)
{
break;
}

int whilecounter = 1;
while (this->dataVector[s+otherPosY][t+otherPosX].Matches(otherTexture.dataVector[otherPosY][otherPosX]))
{
//std::cout << "found next match: " << s+otherPosX << ", " << t+otherPosY << std::endl;
whilecounter++;
if(whilecounter > highestMatch)
{
highestMatch = whilecounter;
}
//std::cout << whilecounter << std::endl;
testPosition++;

if(testPosition == otherTexture.textureInfo.biWidth * otherTexture.textureInfo.biHeight)
{
//found a whole match
counter++;
std::cout << "found: " << counter << "starting at pixel: " << s << "," << t << std::endl;
test = true; //found at least one
break; // <-- You should break the comparison loop here
}

otherPosY = testPosition / otherTexture.textureInfo.biWidth;
otherPosX = testPosition % otherTexture.textureInfo.biWidth;
}
}
}
}
if(!test)
{
std::cout << "Couldnt find a single one. highest match:" << highestMatch << std::endl;
}
else
{
std::cout << "done!" <<std::endl;
}

return test;

You can use the [code=auto:0] tag to preserve indenting in your forum posts :)

I hope this helps

In Topic: Unresolved External

12 November 2010 - 05:05 PM

It would be helpful if you posted the first line of your functions from your .cpp file. For example:

void Render() {
void CleanupDevice() {
etc...

This way we can compare your function definitions, versus what your linker is looking for. This error indicates that they somehow do not match.

PARTNERS