[PyOpenGL-Users] access opengl thru c++
Brought to you by:
mcfletch
From: axel m. <mi...@ho...> - 2009-06-06 14:23:12
|
hello, i am trying to write a simple program to display a cube. my problem is however that when i run the program i can only see a blue background (the background being the value of glClearColor) and not the red cube. note: compile the C program as a shared library and set LD_LIBRARY_PATH=/path/to/lib python code (testGL.py): ------snip---- #!/usr/bin/python import pygame import sys import os import subprocess import ctypes from pygame.locals import * screen = pygame.display.set_mode((1440, 900), HWSURFACE|OPENGL|DOUBLEBUF|FULLSCREEN) Driver = ctypes.CDLL("testGL.so") Driver.resize(ctypes.c_int(1440), ctypes.c_int(900)) Driver.init() kg=True while kg: for event in pygame.event.get(): if event.type == KEYDOWN or event.type == QUIT: kg=False sys.exit() Driver.draw_scene() pygame.display.flip() -------end snip----- C code (testGL.c): -----snip----- #include <GL/gl.h> #include <GL/glu.h> #include <GL/glext.h> #include <math.h> GLvoid resize(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60., (float)width/height, 1., 10000.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } GLvoid init() { glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 1.0, 0.0); glShadeModel(GL_SMOOTH); } GLvoid draw_scene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glBegin(GL_QUADS); glColor3f(1.0, 0.0, 0.0); glVertex3f(100.0, 100.0, 0.0); glVertex3f(200.0, 100.0, 0.0); glVertex3f(200.0, 200.0, 0.0); glVertex3f(100.0, 200.0, 0.0); glEnd(); } -----end snip----- _________________________________________________________________ Vårkänslor och pirr i magen? Hitta din drömpartner här! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 |