1
C / Re: error: invalid use of undefined type 'struct sfTexture'
« on: October 02, 2016, 03:43:10 pm »
Ah...pointers to pointers! I'm new to C so this is something I have not encountered yet. Thanks for the help.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
||=== Build: Release in Crucis (compiler: GNU GCC Compiler) ===|
C:\Users\Platino\Documents\C\Crucis\src\window.c||In function 'loadTextures':|
C:\Users\Platino\Documents\C\Crucis\src\window.c|113|error: invalid use of undefined type 'struct sfTexture'|
C:\Users\Platino\Documents\C\Crucis\src\window.c|113|error: dereferencing pointer to incomplete type|
C:\Users\Platino\Documents\C\Crucis\src\window.c|114|error: invalid use of undefined type 'struct sfTexture'|
C:\Users\Platino\Documents\C\Crucis\src\window.c|114|error: dereferencing pointer to incomplete type|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
sfTexture* textures;
int texturenum = 2;
void loadTexture(void)
{
textures = malloc(sizeof(sfTexture*) * texturenum);
memset(textures, 0, sizeof(sfTexture*) * texturenum);
const char* filepath = "../img/tiles.png";
textures[0] = sfTexture_createFromFile(filepath, NULL); // Line 113
if(textures[0] == NULL) // Line 114
ERROR("Failed to load texture: ", filepath);
}
void getMaxTextureSize()
{
int size = 1;
sf::Texture testtexture;
while(testtexture.create(size, size))
{
size *= 2;
std::cout << "Created texture of size " << testtexture.getSize().x << ", " << testtexture.getSize().y << std::endl;
}
system("pause");
}
uniform sampler2D objtexture;
uniform sampler2D fogtexture;
uniform sampler2D lighttexture;
void main()
{
// Load textures into pixels
vec4 objpixel = texture2D(objtexture, gl_TexCoord[0].xy);
vec4 fogpixel = texture2D(fogtexture, gl_TexCoord[0].xy);
vec4 lightpixel = texture2D(lighttexture, gl_TexCoord[0].xy);
// Draw objects if a lighttexture pixel is fully-transparent
// Otherwise, hide objects behind fog
bool changealpha = bool(ceil(lightpixel.a));
objpixel = vec4((lightpixel.rgb) * float(changealpha) + objpixel.rgb * float(!changealpha), lightpixel.a * float(changealpha) + objpixel.a * float(!changealpha));
objpixel = mix(objpixel, fogpixel, fogpixel.a);
gl_FragColor = objpixel;
}
const std::string shaderdata = "uniform sampler2D objtexture;" \
"uniform sampler2D fogtexture;" \
"uniform sampler2D lighttexture;" \
"" \
"void main()" \
"{" \
" // Load textures into pixels" \
" vec4 objpixel = texture2D(objtexture, gl_TexCoord[0].xy);" \
" vec4 fogpixel = texture2D(fogtexture, gl_TexCoord[0].xy);" \
" vec4 lightpixel = texture2D(lighttexture, gl_TexCoord[0].xy);" \
" " \
" // Draw objects if a lighttexture pixel is fully-transparent" \
" // Otherwise, hide objects behind fog" \
" bool changealpha = bool(ceil(lightpixel.a));" \
" objpixel = vec4((lightpixel.rgb) * float(changealpha) + objpixel.rgb * float(!changealpha), lightpixel.a * float(changealpha) + objpixel.a * float(!changealpha));" \
" objpixel = mix(objpixel, fogpixel, fogpixel.a);" \
" " \
" gl_FragColor = objpixel;" \
"}";
Failed to compile fragment shader:
Fragment shader failed to compile with the following errors:
ERROR: 0:1: error(#131) Syntax error: pre-mature EOF parse error
ERROR: error(#273) 1 compilation errors. No code generated
for(int col = camera.mintile[y]; col <= camera.maxtile[y]; col++)
{
for(int row = camera.mintile[x]; row <= camera.maxtile[x]; row++)
{
Tile* tile = level->getTile(row, col);
sf::IntRect renderrect = { tile->drawclip.left - camera.camerarect.left,
tile->drawclip.top - camera.camerarect.top,
tile->drawclip.width,
tile->drawclip.height};
tilemap.addTile(&renderrect, &tile->imageclip);
}
}
sf::FloatRect initsize(0, 0, 640, 360);
sf::IntRect buffersize(0, 0, initsize.width, initsize.height);
... Do some window resizing and update buffersize ...
sf::Transform tiletransform;
tiletransform.scale(initsize.width / buffersize.width, initsize.height / buffersize.height);
sf::RenderStates tilerender;
tilerender.transform = tiletransform;
window.draw(tilemap, tiletransform);
texturename.copyToImage().saveToFile("filename.png");
sf::Texture newtexture;
newtexture.loadFromFile("filename.png");