Results 1 to 1 of 1
Now I want to realize off-screen under opengl by the way of pixmap, but I can't show it on the screen. Could someone help me ?
codes as follow:
#include ...
- 09-20-2009 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 1
help :to realize offscreen under opengl
Now I want to realize off-screen under opengl by the way of pixmap, but I can't show it on the screen. Could someone help me ?
codes as follow:
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <GL/glx.h>
#include <GL/gl.h>
void DisplayFunc(void);
int main(int argc,char *argv[])
{
GLXContext context;
Display *display;
Pixmap pixmap;
GLXPixmap glxpixmap;
XVisualInfo *vinfo;
FILE *fp;
int y;
unsigned char pixels[3072];
static int attributes[]=
{
GLX_RGBA,
GLX_RED_SIZE,8,
GLX_GREEN_SIZE,8,
GLX_BLUE_SIZE,8,
GLX_DEPTH_SIZE,16,
0,
0
};
display = XOpenDisplay(getenv("DISPLAY"));
vinfo = glXChooseVisual(display,DefaultScreen(display),att ributes);
if (!vinfo)
{
attributes[9] = GLX_DOUBLEBUFFER;
vinfo = glXChooseVisual(display,DefaultScreen(display),att ributes);
}
if (!vinfo)
{
puts("No OpenGL visual available");
return (1);
}
pixmap = XCreatePixmap(display,DefaultRootWindow(display),1 024,1024,vinfo->depth);
glxpixmap = glXCreateGLXPixmap(display,vinfo,pixmap);
context = glXCreateContext(display,vinfo,0,False);
glXMakeCurrent(display,glxpixmap,context);
DisplayFunc();
if((fp = fopen("glxpixmap.ppm","wb")) == NULL)
perror("Unable to creat glxpixmap.ppm");
else
{
fputs("P6\n1024 1024 255\n",fp);
for (y = 1023;y >= 0;y--)
{
glReadPixels(0,y,1024,1,GL_RGB,GL_UNSIGNED_BYTE,pi xels);
fwrite(pixels,1024,3,fp);
}
fclose(fp);
}
glXDestroyContext(display,context);
glXDestroyGLXPixmap(display,glxpixmap);
XFreePixmap(display,pixmap);
XCloseDisplay(display);
return 0;
}
void DisplayFunc(void)
{
int i,j;
glViewport(0,0,1024,1024);
glClearColor(1.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0f,2.0f,-2.0f,2.0f,-10.0f,10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRotatef(CubeRotation[0],1.0f,0.0f,0.0f);
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.5, 1.5, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f( 1.5, 1.5, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.5, -1.5, 0.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(-1.5, -1.5, 0.0);
glEnd();
}


Reply With Quote