Menu Home

opengl

MAC OS下编译OPENGL

MAC OS下编译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

jpeg转换OpenGL Texture

jpeg转换OpenGL Texture #include <stdio.h> #include <unistd.h> #include <jpeglib.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glut.h> void LoadJpgTextureGL(char *file) { FILE *jpegFile; int sizebuf; unsigned char* buffer; unsigned char* texturebuf; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); if((jpegfile = fopen(file,”rb”))==NULL) { perror(“fopen jpeg”); return; } jpeg_stdio_src(&cinfo,jpefile); jpeg_read_header(&cinfo,TRUE); jpeg_start_decompress(&cinfo); sizebuf […]

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; } […]

xlib创建一个openGL简单窗口

void CreateWindow(int width, int height) { XInitThreads(); m_scrWidth = width; m_scrHeight = height; int attr[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, True, GLX_DEPTH_SIZE, 16, None, }; m_dpy = XOpenDisplay(NULL); if (m_dpy == NULL) { cerr << “XOpenDisplay error” << endl; return; } int nelements; GLXFBConfig *fc = glXChooseFBConfig(m_dpy, 0, attr, &nelements); […]

linux下使用C语言生成bitmap

#ifndef SAVEBMP_H #define SAVEBMP_H #include <stdio.h> #include <stdlib.h> typedef long LONG; typedef unsigned char BYTE; typedef unsigned int DWORD; typedef unsigned short WORD; typedef struct { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BMPFILEHEADER_T; typedef struct { DWORD biSize; DWORD biWidth; DWORD biHeight; WORD biPlanes; WORD […]