PNG转换OpenGL Texture

bool loadPngImage(char *name, int *outWidth, int *outHeight, bool *outHasAlpha, GLubyte **outData)
{
	png_structp png_ptr;
	png_infop info_ptr;
	unsigned int sig_read = false;
	int color_type, interlace_type;
	FILE *fp;

	printf("png file : %s\n", name);
	if((fp = fopen(name, "rb")) == NULL)
	{
		printf("%s: open png file error: \n", __FILE__);
		perror("open filed:\n");
		return false;
	}
	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if(NULL == png_ptr)
	{
		fclose(fp);
		return false;
	}
	info_ptr = png_create_info_struct(png_ptr);
	if(NULL == info_ptr)
	{
		fclose(fp);
		return false;
	}
	if(setjmp(png_jmpbuf(png_ptr)))
	{
		png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
		pclose(fp);
		return false;
	}
	png_init_io(png_ptr, fp);
	png_set_sig_bytes(png_ptr, sig_read);
	png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, png_voidp_NULL);
	*outWidth = info_ptr->width;
	*outHeight = info_ptr->height;
	switch(info_ptr->color_type)
	{
		case PNG_COLOR_TYPE_RGBA:
			*outHasAlpha = true;
			break;
		case PNG_COLOR_TYPE_RGB:
			*outHasAlpha = false;
			break;
		default:
			printf("%s: color type: %d not supported\n", __FILE__, info_ptr->color_type);
			png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
			fclose(fp);
			return false;
	}
	unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
	*outData = (unsigned char*)malloc(row_bytes * *outHeight);
	png_bytepp row_pointer = png_get_rows(png_ptr, info_ptr);
	int i;
	for(i = 0; i < *outHeight; i++)
	{
		//note that png is ordered top to buttom,
		//but OpenGL expect it bottom to top
		//so the order swapped
		memcpy(*outData + (row_bytes * (*outHeight - 1 -i)), row_pointer[i], row_bytes);
	}
	png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
	fclose(fp);
	printf("read png finished\n");
	return true;
}

iptables代理上网

OS : opensuse 11.4

需求

eth0 (出外网) : 192.168.1.105   gataway : 192.168.1.1
wlan0 : 192.168.8.1

解决方法

echo 1 > /proc/sys/net/ipv4/ip_forward
iptabes -t nat -A POSTROUTING -o eth0 -s 192.168.80/24 -j SNAT --to 192.168.1.105

MacOS 编译 OpenGL

包含头文件

#include <gl.h>  -->  #include <OpenGL/gl.h>
#include <glu.h>  -->  #include <OpenGL/glu.h>
#include <glut.h> -->  #include <GLUT/glut.h>

编译命令

gcc -framework GLUT -framework OpenGL -framework Cocoa test.c -o test

XCode下导入

/System/Library/Frameworks/OpenGL.framework
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/GLUT.framework

Linux网卡速度及模式设置

Ethtool命令

摘要

ethtool ethX       #查询ethX网口基本设置
ethtool –h         #显示ethtool的命令帮助(help)
ethtool –i ethX    #查询ethX网口的相关信息
ethtool –d ethX    #查询ethX网口注册性信息
ethtool –r ethX    #重置ethX网口到自适应模式
ethtool –S ethX    #查询ethX网口收发包统计
ethtool –s ethX [speed 10|100|1000]         #设置网口速率10/100/1000M
                [duplex half|full]          #设置网口半/全双工
                [autoneg on|off]            #设置网口是否自协商
                [port tp|aui|bnc|mii]       #设置网口类型
                [phyad N]                
                [xcvr internal|exteral]
                [wol p|u|m|b|a|g|s|d...]
                [sopass xx:yy:zz:aa:bb:cc]
                [msglvl N]

举例

[[email protected] /]# ethtool eth1 

可能的返回值

        Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: umbg
        Wake-on: d
        Link detected: yes
[[email protected] /]# ethtool -i eth1

可能的返回值

   driver: e1000
   version: 5.0.43-k1
   firmware-version: N/A
   bus-info: 06:08.1
[[email protected] /]# ethtool -S eth1

可能的返回值

     NIC statistics:
     rx_packets: 58068300
     tx_packets: 87124083
     rx_bytes: 1589713008
     tx_bytes: 2165825901
     rx_errors: 0
     tx_errors: 0
     rx_dropped: 0
     tx_dropped: 0
     multicast: 0
     collisions: 0
     rx_length_errors: 0
     rx_over_errors: 0
     rx_crc_errors: 0
     rx_frame_errors: 0
     rx_fifo_errors: 0
     rx_missed_errors: 0
     tx_aborted_errors: 0
     tx_carrier_errors: 0
     tx_fifo_errors: 0
     tx_heartbeat_errors: 0
     tx_window_errors: 0
[[email protected] /]# ethtool -s eth1 autoneg off speed 100 duplex full 

相关问题

怎样使ethtool设置永久保存在网络设备中?

  • 解决方法一: ethtool设置可通过/etc/sysconfig/network-scripts/ifcfg-ethX文件保存,从而在设备下次启动时激活选项。 例如:ethtool -s eth0 speed 100 duplex full autoneg off 此指令将eth0设备设置为全双工自适应,速度为100Mbs。若要eth0启动时设置这些参数, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth0 ,添加如下一行: ETHTOOL_OPTS=”speed 100 duplex full autoneg off”
  • 解决方法二: 将ethtool设置写入/etc/rc.d/rc.local之中。

ref : http://blog.chinaunix.net/u/1676/showart_1717971.html

Apple Trailer下载

http://trailers.apple.com/trailers/

Apple Trailer真是个好东西,但是默认需要QuickTime,下面提供一种绕过的方法:

wget  --user-agent=QUICKTIME   http://trailers.apple.com/movies/independent/smiley/smiley-clip2_h1080p.mov