/[hegemonie]/hegemonie/ModelViewer/ModelView.m
ViewVC logotype

Diff of /hegemonie/ModelViewer/ModelView.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dam, Tue Jul 1 16:04:02 2003 UTC revision 1.2 by dam, Wed Jul 2 10:10:19 2003 UTC
# Line 24  Line 24 
24  #include <GL/gl.h>  #include <GL/gl.h>
25  #include <GL/glu.h>  #include <GL/glu.h>
26    
27    #include <AppKit/NSOpenGL.h>
28    
29  #include "ModelView.h"  #include "ModelView.h"
30    
31  @implementation ModelView  @implementation ModelView
32    
33  - (void) drawRect: (NSRect)aRect  - (id) initWithFrame: (NSRect)frameRect
34             pixelFormat: (NSOpenGLPixelFormat *)format
35  {  {
36      self = [super initWithFrame: frameRect
37                      pixelFormat: format];
38      if (self != nil)
39        {
40          _init = NO;
41        }
42      
43      return self;
44    }
45    
46    - (BOOL) initGL
47    {
48      glShadeModel (GL_SMOOTH);
49      glClearColor (1.0f, 0.0f, 1.0f, 0.5f);
50      glEnable (GL_DEPTH_TEST);
51    
52      return YES;
53    }
54    
55    - (void) reshape
56    {
57      NSRect sceneBounds;
58      
59      [[self openGLContext] update];
60      sceneBounds = [self bounds];
61      
62      glViewport (0, 0, sceneBounds.size.width, sceneBounds.size.height);
63    glMatrixMode (GL_PROJECTION);    glMatrixMode (GL_PROJECTION);
64    glLoadIdentity ();    glLoadIdentity ();
65    gluOrtho2D (0.0, 800.0, 0.0, 600.0);    gluOrtho2D (0.0, sceneBounds.size.width, 0.0, sceneBounds.size.height);
66      
67    glMatrixMode (GL_MODELVIEW);    glMatrixMode (GL_MODELVIEW);
68    glLoadIdentity ();    glLoadIdentity ();
69    }
70    
71    - (void) drawRect: (NSRect)aRect
72    {
73      if (!_init)
74        {
75          [[self openGLContext] makeCurrentContext];
76          [self initGL];
77          [self reshape];
78          _init = YES;
79        }
80    
81    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
82    
83      glColor3f (1.0f, 1.0f, 1.0f);
84    glBegin (GL_TRIANGLES);    glBegin (GL_TRIANGLES);
85    glVertex2f (0.0, 0.0);    glVertex2f (0.0, 0.0);
86    glVertex2f (400.0, 0.0);    glVertex2f (400.0, 0.0);
87    glVertex2f (400.0, 0.0);    glVertex2f (400.0, 400.0);
88    glEnd ();    glEnd ();
89    
90    //  [[self openGLContext] flushBuffer];    [[self openGLContext] flushBuffer];
91  }  }
92    
93  @end  @end

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26