<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit statischer Klassenfunktion]]></title><description><![CDATA[<p>Ich habe eine als static deklarierte Memberfunktion</p>
<pre><code>void GLButton::load_textures(char *fl_tex_rel_lft, char *fl_tex_rel_rgt, char *fl_tex_rel_mdl,
				  char *fl_tex_psh_lft, char *fl_tex_psh_rgt, char *fl_tex_psh_mdl)
{
	uint16_t hgt1, hgt2, hgt3, hgt4, hgt5;
	uint16_t wth1, wth2, wth3;

	tex_rel_lft = png_load_texture(fl_tex_rel_lft, wth_tex_lft, sz.y);
	tex_rel_rgt = png_load_texture(fl_tex_rel_rgt, wth_tex_rgt, hgt1);
	tex_rel_mdl = png_load_texture(fl_tex_rel_mdl, wth_tex_mdl, hgt2);

	tex_psh_lft = png_load_texture(fl_tex_rel_lft, wth1, hgt3);
	tex_psh_rgt = png_load_texture(fl_tex_rel_rgt, wth2, hgt4);
	tex_psh_mdl = png_load_texture(fl_tex_rel_mdl, wth3, hgt5);

	printf(&quot;%ux%u\n&quot;,wth_tex_lft, sz.y);
	printf(&quot;%ux%u\n&quot;,wth_tex_rgt, hgt1);
	printf(&quot;%ux%u\n&quot;,wth_tex_mdl, hgt2);
	printf(&quot;%ux%u\n&quot;,wth1, hgt3);
	printf(&quot;%ux%u\n&quot;,wth2, hgt4);
	printf(&quot;%ux%u\n&quot;,wth3, hgt5);

}
</code></pre>
<p>Hierbei sind</p>
<pre><code>wth_tex_lft
wth_tex_mdl
wth_tex_rgt
sz
</code></pre>
<p>als static deklarierte Membervariablen</p>
<p>Die Funktion wird in meinem Quelltext insgesamt nur einmal aufgerufen und ich bekomme dabei folgende Ausgabe:</p>
<pre><code>40x40
40x0
40x0
0x0
0x0
40x40
</code></pre>
<p>Eigentlich sollte überall 40x40 herauskommen. Wenn ich die Variablen hgt1, hgt2, hgt3, ... und wth1, wth2 und wth3 als static deklariere bekomme ich das gewünschte Ergebniss, warum?</p>
<pre><code>static	uint16_t hgt1, hgt2, hgt3, hgt4, hgt5;
static	uint16_t wth1, wth2, wth3;
</code></pre>
<pre><code>40x40
40x40
40x40
40x40
40x40
40x40
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/319845/problem-mit-statischer-klassenfunktion</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 20:59:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319845.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Sep 2013 09:46:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 09:46:09 GMT]]></title><description><![CDATA[<p>Ich habe eine als static deklarierte Memberfunktion</p>
<pre><code>void GLButton::load_textures(char *fl_tex_rel_lft, char *fl_tex_rel_rgt, char *fl_tex_rel_mdl,
				  char *fl_tex_psh_lft, char *fl_tex_psh_rgt, char *fl_tex_psh_mdl)
{
	uint16_t hgt1, hgt2, hgt3, hgt4, hgt5;
	uint16_t wth1, wth2, wth3;

	tex_rel_lft = png_load_texture(fl_tex_rel_lft, wth_tex_lft, sz.y);
	tex_rel_rgt = png_load_texture(fl_tex_rel_rgt, wth_tex_rgt, hgt1);
	tex_rel_mdl = png_load_texture(fl_tex_rel_mdl, wth_tex_mdl, hgt2);

	tex_psh_lft = png_load_texture(fl_tex_rel_lft, wth1, hgt3);
	tex_psh_rgt = png_load_texture(fl_tex_rel_rgt, wth2, hgt4);
	tex_psh_mdl = png_load_texture(fl_tex_rel_mdl, wth3, hgt5);

	printf(&quot;%ux%u\n&quot;,wth_tex_lft, sz.y);
	printf(&quot;%ux%u\n&quot;,wth_tex_rgt, hgt1);
	printf(&quot;%ux%u\n&quot;,wth_tex_mdl, hgt2);
	printf(&quot;%ux%u\n&quot;,wth1, hgt3);
	printf(&quot;%ux%u\n&quot;,wth2, hgt4);
	printf(&quot;%ux%u\n&quot;,wth3, hgt5);

}
</code></pre>
<p>Hierbei sind</p>
<pre><code>wth_tex_lft
wth_tex_mdl
wth_tex_rgt
sz
</code></pre>
<p>als static deklarierte Membervariablen</p>
<p>Die Funktion wird in meinem Quelltext insgesamt nur einmal aufgerufen und ich bekomme dabei folgende Ausgabe:</p>
<pre><code>40x40
40x0
40x0
0x0
0x0
40x40
</code></pre>
<p>Eigentlich sollte überall 40x40 herauskommen. Wenn ich die Variablen hgt1, hgt2, hgt3, ... und wth1, wth2 und wth3 als static deklariere bekomme ich das gewünschte Ergebniss, warum?</p>
<pre><code>static	uint16_t hgt1, hgt2, hgt3, hgt4, hgt5;
static	uint16_t wth1, wth2, wth3;
</code></pre>
<pre><code>40x40
40x40
40x40
40x40
40x40
40x40
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2350451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350451</guid><dc:creator><![CDATA[rejak]]></dc:creator><pubDate>Thu, 05 Sep 2013 09:46:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 10:10:33 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> DU hast die Variablen doch gar net initialisiert, da kommt wohl nie 40 raus. Du musst <code>=40</code> dazuschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350454</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Thu, 05 Sep 2013 10:10:33 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 10:14:14 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> DU hast die Variablen doch gar net initialisiert, da kommt wohl nie 40 raus. Du musst <code>=40</code> dazuschreiben.</p>
</blockquote>
<p>Vielleicht werden sie per Referenz an png_load_texture übergeben?</p>
<p>Man weiß zu wenig, um hier sinnvoll antworten zu können.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350455</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 05 Sep 2013 10:14:14 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 10:14:44 GMT]]></title><description><![CDATA[<p>Die Variablen initialisieren macht die Funktion</p>
<pre><code>GLuint png_load_texture(const char *file, uint16_t &amp;width, uint16_t &amp;height)
{
	png_byte header[8];

	FILE *fp = fopen(file, &quot;rb&quot;);
	if (fp == 0)
	{
		perror(file);
		return 0;
	}

	// read the header
	fread(header, 1, 8, fp);

	if (png_sig_cmp(header, 0, 8))
	{
		fprintf(stderr, &quot;error: %s is not a PNG.\n&quot;, file);
		fclose(fp);
		return 0;
	}

	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (!png_ptr)
	{
		fprintf(stderr, &quot;error: png_create_read_struct returned 0.\n&quot;);
		fclose(fp);
		return 0;
	}

	// create png info struct
	png_infop info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr)
	{
		fprintf(stderr, &quot;error: png_create_info_struct returned 0.\n&quot;);
		png_destroy_read_struct(&amp;png_ptr, (png_infopp)NULL, (png_infopp)NULL);
		fclose(fp);
		return 0;
	}

	// create png info struct
	png_infop end_info = png_create_info_struct(png_ptr);
	if (!end_info)
	{
		fprintf(stderr, &quot;error: png_create_info_struct returned 0.\n&quot;);
		png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, (png_infopp) NULL);
		fclose(fp);
		return 0;
	}

	// the code in this if statement gets called if libpng encounters an error
	if (setjmp(png_jmpbuf(png_ptr))) {
		fprintf(stderr, &quot;error from libpng\n&quot;);
		png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
		fclose(fp);
		return 0;
	}

	// init png reading
	png_init_io(png_ptr, fp);

	// let libpng know you already read the first 8 bytes
	png_set_sig_bytes(png_ptr, 8);

	// read all the info up to the image data
	png_read_info(png_ptr, info_ptr);

	// variables to pass to get info
	int bit_depth, color_type;

	// get info about png
	png_get_IHDR(png_ptr, info_ptr, (png_uint_32*)&amp;width, (png_uint_32*)&amp;height, &amp;bit_depth, &amp;color_type,
		NULL, NULL, NULL);

	// Update the png info struct.
	png_read_update_info(png_ptr, info_ptr);

	// Row size in bytes.
	int rowbytes = png_get_rowbytes(png_ptr, info_ptr);

	// glTexImage2d requires rows to be 4-byte aligned
	rowbytes += 3 - ((rowbytes-1) % 4);

	// Allocate the image_data as a big block, to be given to opengl
	png_byte * image_data;
	image_data = (png_byte *)malloc(rowbytes * height * sizeof(png_byte)+15);
	if (image_data == NULL)
	{
		fprintf(stderr, &quot;error: could not allocate memory for PNG image data\n&quot;);
		png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
		fclose(fp);
		return 0;
	}

	// row_pointers is for pointing to image_data for reading the png with libpng
	png_bytep * row_pointers = (png_bytep *)malloc(height * sizeof(png_bytep));
	if (row_pointers == NULL)
	{
		fprintf(stderr, &quot;error: could not allocate memory for PNG row pointers\n&quot;);
		png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
		free(image_data);
		fclose(fp);
		return 0;
	}

	// set the individual row_pointers to point at the correct offsets of image_data
	int i;
	for (i = 0; i &lt; height; i++)
	{
		row_pointers[height - 1 - i] = image_data + i * rowbytes;
	}

	// read the png into image_data through row_pointers
	png_read_image(png_ptr, row_pointers);

	// Generate the OpenGL texture object
	GLuint texture;
	glGenTextures(1, &amp;texture);
	glBindTexture(GL_TEXTURE_2D, texture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	// clean up
	png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
	free(image_data);
	free(row_pointers);
	fclose(fp);
	return texture;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2350456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350456</guid><dc:creator><![CDATA[rejak]]></dc:creator><pubDate>Thu, 05 Sep 2013 10:14:44 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 10:26:59 GMT]]></title><description><![CDATA[<p>Falsches Board, übrigens.</p>
<blockquote>
<p>(png_uint_32*)&amp;width</p>
</blockquote>
<p>AFAICS Ganz doofe Idee. <code>width</code> ist doch nur 16 Bit groß.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350458</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 05 Sep 2013 10:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit statischer Klassenfunktion on Thu, 05 Sep 2013 10:27:40 GMT]]></title><description><![CDATA[<p>rejak schrieb:</p>
<blockquote>
<pre><code>GLuint png_load_texture(const char *file, uint16_t &amp;width, uint16_t &amp;height)
	// get info about png
	png_get_IHDR(png_ptr, info_ptr, (png_uint_32*)&amp;width, (png_uint_32*)&amp;height, &amp;bit_depth, &amp;color_type,
		NULL, NULL, NULL);
</code></pre>
</blockquote>
<p>Na das hast du dir wohl ein bisschen zu einfach vorgestellt. Einfach mal nach png_uint_32* casten und auf ein Wunder hoffen? Nein, das musst du anders lösen, z.B.</p>
<pre><code>png_uint32 tempwidth, tempheight;
  png_get_IHDR(png_ptr, info_ptr, &amp;tempwidth, &amp;tempheight, &amp;bit_depth, &amp;color_type, NULL, NULL, NULL);
  height = static_cast&lt;uint16_t&gt;(tempheight);
  width = static_cast&lt;uint16_t&gt;(tempwidth);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2350459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350459</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 05 Sep 2013 10:27:40 GMT</pubDate></item></channel></rss>