Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OODebugGLDrawing.m
Go to the documentation of this file.
1/*
2
3OODebugDrawing.m
4
5
6Copyright (C) 2007-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#import "OODebugGLDrawing.h"
29#import "OOMacroOpenGL.h"
30#import "OOMaterial.h"
31
32
33#ifndef OODEBUGLDRAWING_DISABLE
34
36{
37 GLfloat r, g, b, a;
38
40
41 if (EXPECT_NOT(color == nil)) color = [OOColor lightGrayColor];
42 [color getRed:&r green:&g blue:&b alpha:&a];
43 OOGL(glColor4f(r, g, b, a));
44}
45
46
47void OODebugDrawColoredBoundingBoxBetween(Vector min, Vector max, OOColor *color)
48{
51
52 ApplyColor(color);
53 OOGLBEGIN(GL_LINE_LOOP);
54 glVertex3f(min.x, min.y, min.z);
55 glVertex3f(max.x, min.y, min.z);
56 glVertex3f(max.x, max.y, min.z);
57 glVertex3f(min.x, max.y, min.z);
58 glVertex3f(min.x, max.y, max.z);
59 glVertex3f(max.x, max.y, max.z);
60 glVertex3f(max.x, min.y, max.z);
61 glVertex3f(min.x, min.y, max.z);
62 OOGLEND();
63 OOGLBEGIN(GL_LINES);
64 glVertex3f(max.x, min.y, min.z);
65 glVertex3f(max.x, min.y, max.z);
66 glVertex3f(max.x, max.y, min.z);
67 glVertex3f(max.x, max.y, max.z);
68 glVertex3f(min.x, min.y, min.z);
69 glVertex3f(min.x, max.y, min.z);
70 glVertex3f(min.x, min.y, max.z);
71 glVertex3f(min.x, max.y, max.z);
72 OOGLEND();
73
75}
76
77
78void OODebugDrawColoredLine(Vector start, Vector end, OOColor *color)
79{
82
83 ApplyColor(color);
84
85 OOGLBEGIN(GL_LINES);
86 glVertex3f(start.x, start.y, start.z);
87 glVertex3f(end.x, end.y, end.z);
88 OOGLEND();
89
91}
92
93
94void OODebugDrawBasis(Vector position, GLfloat scale)
95{
98
99 OOGLBEGIN(GL_LINES);
100 glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
101 glVertex3f(position.x, position.y, position.z);
102 glVertex3f(position.x + scale, position.y, position.z);
103
104 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
105 glVertex3f(position.x, position.y, position.z);
106 glVertex3f(position.x, position.y + scale, position.z);
107
108 glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
109 glVertex3f(position.x, position.y, position.z);
110 glVertex3f(position.x, position.y, position.z + scale);
111 OOGLEND();
112
113 OODebugEndWireframe(state);
114}
115
116
117void OODebugDrawPoint(Vector position, OOColor *color)
118{
121
122 ApplyColor(color);
124
125 OOGLBEGIN(GL_POINTS);
126 glVertex3f(position.x, position.y, position.z);
127 OOGLEND();
128
129 OODebugEndWireframe(state);
130}
131
132
134{
136
137 OODebugWFState state = { .material = [OOMaterial current] };
139
140 OOGL(glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT));
141
142 OOGL(glDisable(GL_LIGHTING));
143 OOGL(glDisable(GL_TEXTURE_2D));
144 OOGL(glDisable(GL_FOG));
145 if (ignoreZ)
146 {
147 OOGL(glDisable(GL_DEPTH_TEST));
148 OOGL(glDepthMask(GL_FALSE));
149 }
150 else
151 {
152 OOGL(glEnable(GL_DEPTH_TEST));
153 OOGL(glDepthMask(GL_TRUE));
154 }
155
156 OOGL(GLScaledLineWidth(1.0f));
157
158 return state;
159}
160
161
163{
165 OOGL(glPopAttrib());
166 [state.material apply];
167}
168
169#endif
void OODebugEndWireframe(OODebugWFState state)
OOINLINE void ApplyColor(OOColor *color)
void OODebugDrawColoredLine(Vector start, Vector end, OOColor *color)
void OODebugDrawBasis(Vector position, GLfloat scale)
void OODebugDrawPoint(Vector position, OOColor *color)
void OODebugDrawColoredBoundingBoxBetween(Vector min, Vector max, OOColor *color)
OODebugWFState OODebugBeginWireframe(BOOL ignoreZ)
#define EXPECT_NOT(x)
#define OOINLINE
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:253
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:218
#define OOGL(statement)
Definition OOOpenGL.h:251
void GLScaledPointSize(GLfloat size)
Definition OOOpenGL.m:225
#define OOGLEND
Definition OOOpenGL.h:254
return nil
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:368
OOColor * lightGrayColor()
Definition OOColor.m:250
OOMaterial * current()
Definition OOMaterial.m:88
void applyNone()
Definition OOMaterial.m:80