Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Topics - DragonDePlatino

Pages: [1]
1
C / [SOLVED] error: invalid use of undefined type 'struct sfTexture'
« on: October 02, 2016, 04:37:50 am »
Hi! I just picked up C and CSFML and I'm having some issues loading textures. My compiler is telling me that sfTexture is an incomplete type. The error in question:

Code: [Select]
||=== 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)) ===|

From what I understand, there is a declaration but no implementation of sfTexture? I'm confused as to why this is an issue. I've been using sfRenderWindow, sfRectangleShape and sfVertexArray from the same header with no problems. Am I doing something wrong? Here is the simplified code from window.c:

Code: [Select]
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);
}

There's a lot going on with loading filenames from JSON and such, but I've triple-checked that's working correctly. Have I not correctly installed CSFML?

2
Graphics / [SOLVED] Loading a shader: pre-mature EOF parse error
« on: July 12, 2016, 02:53:55 am »
For my game project, I have a fog of war shader that hides out-of-view enemies:

Code: [Select]
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;
}

When running the program from Code::Blocks, everything works fine. Running the executable, it isn't finding fog.frag file. I could include the fog.frag in the download, but I'd rather not have users cheat and edit the shader. As a solution, I tried embedding the shader in my program like the example shown here.

After running it through a Notepad++ macro to eliminate any human error, my shader now looks like this:

Code: [Select]
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;" \
"}";

Unfortunately, if I compile, I get this error:

Code: [Select]
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

If I print out my shaderdata string, it looks just fine. If I remove all of the comments, line breaks and empty lines, I get the same exact error. Looking at the special characters in Notepad++, all I see are line breaks, tabs and spaces. Could someone please explain what I'm doing wrong?

3
Graphics / [SOLVED] Incorrect scaling of custom VertexArray
« on: June 30, 2016, 01:05:20 am »
Hello! I'm having some problems with the scaling of a custom VertexArray.

In my engine I have a texture for tiles, objects and lights. Tiles and objects are drawn via a custom VertexArray like the one shown here. Lights are drawn using sf::Shape. I draw the objects, tiles and lights to their textures, then I pass everything through a shader. The result is a fog of war system that masks out of view objects:



If I resize the window all of my textures resize accordingly and I can see a further distance:



Here's my problem: I don't want to draw my tile VertexArray to a texture then pass it through my shader. It seems wasteful because I'm not modifying it in my shader. Instead, I want to draw my tile VertexArray directly to the screen then draw the shader's texture over that. If I do this, it works just fine (like in the first image). The problem is when I resize the window. This happens:



Everything passed through the shader resizes correctly, but the tile VertexArray does not. The larger I resize the window, the further offscreen the tile VertexArray stretches. The smaller I make the window, the less the VertexArray takes up the screen.

If I debug my VertexArray, everything seems to be fine. Each vertex is still 32x32 in size and the larger the screen is, the more vertexes are added. I think SFML might be forcibly scaling my tile VertexArray which I do not want! >:(

For the record, I have also tried rendering my tile VertexArray to a texture, making a sprite from that and rendering it to the window. I get the same bad results.

Pages: [1]