T
Hi
für eine bessere Darstellung eines Problems sehe ich mich gezwungen mit Glut 2 Fenster zu rendern. Ich würde alles gerne in einem Hauptfenster (2D) mit einem Subwindow (3D) erledigen. Irgendwie funktionierts nicht und ich hab ehrlich gesagt keinen Schimmer woran es liegt.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <GL/glut.h>
#define WND_HEIGHT 300
#define WND_WIDTH 512
int mainWnd, subWnd;
void mainDisp(void)
{
glutSetWindow (mainWnd);
glClearColor (1, 1, 1, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glBegin(GL_LINES);
glColor3f(.8, .4, .4);
glVertex3f(0,0,0);
glVertex3f(2,0,0);
glColor3f(.4, .8, .4);
glVertex3f(0,0,0);
glVertex3f(0,2,0);
glEnd();
glutSwapBuffers();
}
void subDisp(void)
{
glutSetWindow (subWnd);
glClearColor (0.25, 0.25, 0.25, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glBegin(GL_LINES);
glColor3f(.8, .4, .4);
glVertex3f(0,0,0);
glVertex3f(2,0,0);
glColor3f(.4, .8, .4);
glVertex3f(0,0,0);
glVertex3f(0,2,0);
glEnd();
glutSwapBuffers();
}
void mainReshape(int w, int h)
{
if(!h) h = 1;
glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0, WND_WIDTH/2, 0, WND_HEIGHT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glutSetWindow (subWnd);
glutReshapeWindow (WND_WIDTH / 2, WND_HEIGHT );
glutPositionWindow (WND_WIDTH/2, 0);
glutSetWindow (mainWnd);
}
void subReshape(int w, int h)
{
GLfloat nRange = 10.0f;
float ar = (float)h/(float)w;
if(!h) h = 1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <=h)
glOrtho(-nRange, nRange, -nRange*ar, nRange*ar, -nRange, nRange);
else
glOrtho(-nRange*ar, nRange*ar, -nRange, nRange, -nRange, nRange);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(void)
{
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition (100, 100);
glutInitWindowSize (WND_WIDTH, WND_HEIGHT);
mainWnd= glutCreateWindow ("test");
glutDisplayFunc (mainDisp);
glutReshapeFunc (mainReshape);
subWnd = glutCreateSubWindow (mainWnd, WND_WIDTH/2, 0, WND_WIDTH / 2, WND_HEIGHT );
glutDisplayFunc (subDisp);
glutReshapeFunc (subReshape);
glutMainLoop ();
return 0;
}