Several rad2deg conversions for glRotate

This commit is contained in:
bart@bartbes.ath.cx
2009-11-30 08:21:48 +01:00
parent 692fd9a890
commit af01b840a1
4 changed files with 79 additions and 79 deletions
+55 -55
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2009 LOVE Development Team * Copyright (c) 2006-2009 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -64,7 +64,7 @@ namespace opengl
// Check if mode is supported // Check if mode is supported
int bpp = SDL_VideoModeOK(width, height, 32, sdlflags); int bpp = SDL_VideoModeOK(width, height, 32, sdlflags);
return (bpp >= 16); return (bpp >= 16);
} }
DisplayState Graphics::saveState() DisplayState Graphics::saveState()
@@ -151,7 +151,7 @@ namespace opengl
// Get caption. // Get caption.
// Special case for fullscreen -> windowed. Windows XP did not // Special case for fullscreen -> windowed. Windows XP did not
// work well with "normal" display mode change in this case. // work well with "normal" display mode change in this case.
// The application window does leave fullscreen, but the desktop // The application window does leave fullscreen, but the desktop
// resolution does not revert to the correct one. Restarting the // resolution does not revert to the correct one. Restarting the
// SDL video subsystem does the trick, though. // SDL video subsystem does the trick, though.
@@ -224,7 +224,7 @@ namespace opengl
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
// Enable textures // Enable textures
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
// Set the viewport to top-left corner // Set the viewport to top-left corner
glViewport(0,0, width, height); glViewport(0,0, width, height);
@@ -261,10 +261,10 @@ namespace opengl
bool Graphics::toggleFullscreen() bool Graphics::toggleFullscreen()
{ {
// Try to do the change. // Try to do the change.
if(!setMode(currentMode.width, if(!setMode(currentMode.width,
currentMode.height, currentMode.height,
!currentMode.fullscreen, !currentMode.fullscreen,
currentMode.vsync, currentMode.vsync,
currentMode.fsaa)) currentMode.fsaa))
return false; return false;
currentMode.fullscreen = !currentMode.fullscreen; currentMode.fullscreen = !currentMode.fullscreen;
@@ -395,10 +395,10 @@ namespace opengl
image->release(); image->release();
return 0; return 0;
} }
return image; return image;
} }
Quad * Graphics::newQuad(int x, int y, int w, int h, int sw, int sh) Quad * Graphics::newQuad(int x, int y, int w, int h, int sw, int sh)
{ {
Quad::Viewport v; Quad::Viewport v;
@@ -458,9 +458,9 @@ namespace opengl
glGetFloatv(GL_CURRENT_COLOR, c); glGetFloatv(GL_CURRENT_COLOR, c);
Color t; Color t;
t.r = (unsigned char)(255.0f*c[0]); t.r = (unsigned char)(255.0f*c[0]);
t.g = (unsigned char)(255.0f*c[1]); t.g = (unsigned char)(255.0f*c[1]);
t.b = (unsigned char)(255.0f*c[2]); t.b = (unsigned char)(255.0f*c[2]);
t.a = (unsigned char)(255.0f*c[3]); t.a = (unsigned char)(255.0f*c[3]);
return t; return t;
@@ -477,9 +477,9 @@ namespace opengl
glGetFloatv(GL_COLOR_CLEAR_VALUE, c); glGetFloatv(GL_COLOR_CLEAR_VALUE, c);
Color t; Color t;
t.r = (unsigned char)(255.0f*c[0]); t.r = (unsigned char)(255.0f*c[0]);
t.g = (unsigned char)(255.0f*c[1]); t.g = (unsigned char)(255.0f*c[1]);
t.b = (unsigned char)(255.0f*c[2]); t.b = (unsigned char)(255.0f*c[2]);
t.a = (unsigned char)(255.0f*c[3]); t.a = (unsigned char)(255.0f*c[3]);
return t; return t;
@@ -525,7 +525,7 @@ namespace opengl
else // mode = COLOR_REPLACE else // mode = COLOR_REPLACE
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} }
Graphics::BlendMode Graphics::getBlendMode() Graphics::BlendMode Graphics::getBlendMode()
{ {
GLint dst, src; GLint dst, src;
@@ -562,7 +562,7 @@ namespace opengl
{ {
glEnable (GL_LINE_SMOOTH); glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
} }
} }
void Graphics::setLine( float width, Graphics::LineStyle style ) void Graphics::setLine( float width, Graphics::LineStyle style )
@@ -611,7 +611,7 @@ namespace opengl
{ {
if(glIsEnabled(GL_LINE_STIPPLE) == GL_FALSE) if(glIsEnabled(GL_LINE_STIPPLE) == GL_FALSE)
return 0; return 0;
GLint factor, pattern; GLint factor, pattern;
glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &pattern); glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &pattern);
glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &factor); glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &factor);
@@ -677,7 +677,7 @@ namespace opengl
{ {
int lines = 0; int lines = 0;
text = ""; text = "";
for(unsigned int i = 0; i < strlen(str); i++) for(unsigned int i = 0; i < strlen(str); i++)
{ {
if(str[i] == '\n') if(str[i] == '\n')
@@ -689,7 +689,7 @@ namespace opengl
else else
text += str[i]; text += str[i];
} }
if(text != "") // Print the last text (if applicable). if(text != "") // Print the last text (if applicable).
currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight())); currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()));
} }
@@ -730,7 +730,7 @@ namespace opengl
std::string text = ""; std::string text = "";
float width = 0; float width = 0;
float lines = 0; float lines = 0;
for(unsigned int i = 0; i < strlen(str); i++) for(unsigned int i = 0; i < strlen(str); i++)
{ {
if(str[i] == '\n') if(str[i] == '\n')
@@ -740,15 +740,15 @@ namespace opengl
case ALIGN_LEFT: case ALIGN_LEFT:
currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
currentFont->print(text, (x + (wrap - currentFont->getWidth(text))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(text, (x + (wrap - currentFont->getWidth(text))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
currentFont->print(text, ceil(x + ((wrap - currentFont->getWidth(text)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) ); currentFont->print(text, ceil(x + ((wrap - currentFont->getWidth(text)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) );
break; break;
default: // A copy of the left align code. Kept separate in case an error message is wanted. default: // A copy of the left align code. Kept separate in case an error message is wanted.
currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
@@ -761,37 +761,37 @@ namespace opengl
else else
{ {
width += currentFont->getWidth(str[i]); width += currentFont->getWidth(str[i]);
if(width > wrap && text.find(" ") != std::string::npos) // If there doesn't exist a space, then ignore the wrap limit. if(width > wrap && text.find(" ") != std::string::npos) // If there doesn't exist a space, then ignore the wrap limit.
{ {
// Seek back to the nearest space and print that. // Seek back to the nearest space and print that.
unsigned int space = (unsigned int)text.find_last_of(' '); unsigned int space = (unsigned int)text.find_last_of(' ');
std::string temp = text.substr(0, space); std::string temp = text.substr(0, space);
switch(align) switch(align)
{ {
case ALIGN_LEFT: case ALIGN_LEFT:
currentFont->print(temp, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(temp, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
currentFont->print(temp, (x + (wrap - currentFont->getWidth(temp))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(temp, (x + (wrap - currentFont->getWidth(temp))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
currentFont->print(temp, ceil(x + ((wrap - currentFont->getWidth(temp)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) ); currentFont->print(temp, ceil(x + ((wrap - currentFont->getWidth(temp)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) );
break; break;
default: // A copy of the left align code. Kept separate in case an error message is wanted. default: // A copy of the left align code. Kept separate in case an error message is wanted.
currentFont->print(temp, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(temp, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
} }
text = text.substr(space + 1); text = text.substr(space + 1);
width = currentFont->getWidth(text); width = currentFont->getWidth(text);
lines++; lines++;
} }
text += str[i]; text += str[i];
} }
} // for } // for
@@ -803,20 +803,20 @@ namespace opengl
case ALIGN_LEFT: case ALIGN_LEFT:
currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
currentFont->print(text, (x + (wrap - currentFont->getWidth(text))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) ); currentFont->print(text, (x + (wrap - currentFont->getWidth(text))), y + (lines * currentFont->getHeight() * currentFont->getLineHeight()) );
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
currentFont->print(text, ceil(x + ((wrap - currentFont->getWidth(text)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) ); currentFont->print(text, ceil(x + ((wrap - currentFont->getWidth(text)) / 2)), ceil(y + (lines * currentFont->getHeight() * currentFont->getLineHeight())) );
break; break;
default: // A copy of the left align code. Kept separate in case an error message is wanted. default: // A copy of the left align code. Kept separate in case an error message is wanted.
currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight())); currentFont->print(text, x, y + (lines * currentFont->getHeight() * currentFont->getLineHeight()));
break; break;
} }
} }
} }
} }
@@ -885,7 +885,7 @@ namespace opengl
{ {
case DRAW_LINE: case DRAW_LINE:
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex2f(x, y); glVertex2f(x, y);
glVertex2f(x, y+h); glVertex2f(x, y+h);
glVertex2f(x+w, y+h); glVertex2f(x+w, y+h);
glVertex2f(x+w, y); glVertex2f(x+w, y);
@@ -895,7 +895,7 @@ namespace opengl
default: default:
case DRAW_FILL: case DRAW_FILL:
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(x, y); glVertex2f(x, y);
glVertex2f(x, y+h); glVertex2f(x, y+h);
glVertex2f(x+w, y+h); glVertex2f(x+w, y+h);
glVertex2f(x+w, y); glVertex2f(x+w, y);
@@ -917,7 +917,7 @@ namespace opengl
{ {
case DRAW_LINE: case DRAW_LINE:
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex2f(x1, y1); glVertex2f(x1, y1);
glVertex2f(x2, y2); glVertex2f(x2, y2);
glVertex2f(x3, y3); glVertex2f(x3, y3);
glVertex2f(x4, y4); glVertex2f(x4, y4);
@@ -1009,7 +1009,7 @@ namespace opengl
return luaL_error(L, "Error: number type or table expected."); return luaL_error(L, "Error: number type or table expected.");
} }
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
@@ -1022,7 +1022,7 @@ namespace opengl
glVertex2f((GLfloat)lua_tonumber(L, i), (GLfloat)lua_tonumber(L, i+1)); glVertex2f((GLfloat)lua_tonumber(L, i), (GLfloat)lua_tonumber(L, i+1));
break; break;
case LUA_TTABLE: case LUA_TTABLE:
lua_pushnil(L); lua_pushnil(L);
while (true) while (true)
{ {
if(lua_next(L, 2) == 0) break; if(lua_next(L, 2) == 0) break;
@@ -1048,29 +1048,29 @@ namespace opengl
{ {
int w = getWidth(); int w = getWidth();
int h = getHeight(); int h = getHeight();
int row = 4*w; int row = 4*w;
int size = row*h; int size = row*h;
GLubyte * pixels = new GLubyte[size]; GLubyte * pixels = new GLubyte[size];
GLubyte * screenshot = new GLubyte[size]; GLubyte * screenshot = new GLubyte[size];
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// OpenGL sucks and reads pixels from the lower-left. Let's fix that. // OpenGL sucks and reads pixels from the lower-left. Let's fix that.
GLubyte *src = pixels - row, *dst = screenshot + size; GLubyte *src = pixels - row, *dst = screenshot + size;
for (int i = 0; i < h; ++i) { for (int i = 0; i < h; ++i) {
memcpy(dst-=row, src+=row, row); memcpy(dst-=row, src+=row, row);
} }
love::image::ImageData * img = image->newImageData(w, h, (void*)screenshot); love::image::ImageData * img = image->newImageData(w, h, (void*)screenshot);
delete [] pixels; delete [] pixels;
delete [] screenshot; delete [] screenshot;
return img; return img;
} }
@@ -1086,7 +1086,7 @@ namespace opengl
void Graphics::rotate(float r) void Graphics::rotate(float r)
{ {
glRotatef(r, 0, 0, 1); glRotatef(r * 57.29578f, 0, 0, 1);
} }
void Graphics::scale(float x, float y) void Graphics::scale(float x, float y)
+16 -16
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2009 LOVE Development Team * Copyright (c) 2006-2009 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -25,17 +25,17 @@
using std::string; using std::string;
namespace love namespace love
{ {
namespace graphics namespace graphics
{ {
namespace opengl namespace opengl
{ {
ImageFont::ImageFont(Image * image, std::string glyphs) ImageFont::ImageFont(Image * image, std::string glyphs)
: Font(0), glyphs(glyphs), image(image) : Font(0), glyphs(glyphs), image(image)
{ {
image->retain(); image->retain();
} }
ImageFont::~ImageFont() ImageFont::~ImageFont()
{ {
@@ -58,7 +58,7 @@ namespace opengl
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0.0f); glTranslatef(x, y, 0.0f);
glRotatef(angle, 0, 0, 1.0f); glRotatef(angle * 57.29578f, 0, 0, 1.0f);
glScalef(sx, sy, 1.0f); glScalef(sx, sy, 1.0f);
GLuint OpenGLFont = list; GLuint OpenGLFont = list;
@@ -87,16 +87,16 @@ namespace opengl
{ {
unloadVolatile(); unloadVolatile();
} }
bool ImageFont::loadVolatile() bool ImageFont::loadVolatile()
{ {
love::image::pixel * pixels = (love::image::pixel *)(image->getData()->getData()); love::image::pixel * pixels = (love::image::pixel *)(image->getData()->getData());
// Reading texture data begins // Reading texture data begins
size = (int)image->getHeight(); size = (int)image->getHeight();
for(unsigned int i = 0; i < MAX_CHARS; i++) positions[i] = -1; for(unsigned int i = 0; i < MAX_CHARS; i++) positions[i] = -1;
love::image::pixel spacer = pixels[0]; love::image::pixel spacer = pixels[0];
unsigned int current = 0; unsigned int current = 0;
int width = 0; int width = 0;
@@ -114,9 +114,9 @@ namespace opengl
break; break;
} }
} }
for(int i = firstchar; i != (int)image->getWidth(); i++) for(int i = firstchar; i != (int)image->getWidth(); i++)
{ {
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a) if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
{ {
if(width != 0) // this means we have found the end of our current character if(width != 0) // this means we have found the end of our current character
@@ -128,7 +128,7 @@ namespace opengl
widths[(int)glyphs[current]] = width - 1; widths[(int)glyphs[current]] = width - 1;
positions[(int)glyphs[current]] = i - width; positions[(int)glyphs[current]] = i - width;
} }
width = 0; width = 0;
//space++; // start counting the spacing //space++; // start counting the spacing
} }
@@ -181,7 +181,7 @@ namespace opengl
float y = 1.0; float y = 1.0;
float w = (float)widths[i]; float w = (float)widths[i];
float h = (float)size+1; float h = (float)size+1;
image->bind(); image->bind();
float xTex = x/(float)image->getWidth(); float xTex = x/(float)image->getWidth();
@@ -196,7 +196,7 @@ namespace opengl
glTexCoord2f(xTex+wTex,yTex+hTex); glVertex2f(w,h); glTexCoord2f(xTex+wTex,yTex+hTex); glVertex2f(w,h);
glTexCoord2f(xTex+wTex,yTex); glVertex2f(w,0); glTexCoord2f(xTex+wTex,yTex); glVertex2f(w,0);
glEnd(); glEnd();
glTranslatef((float)widths[i] + ((float)spacing[i] * mSpacing), 0, 0); glTranslatef((float)widths[i] + ((float)spacing[i] * mSpacing), 0, 0);
} }
else else
@@ -397,7 +397,7 @@ namespace opengl
glPushAttrib(GL_CURRENT_BIT); glPushAttrib(GL_CURRENT_BIT);
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
glRotatef(angle, 0, 0, 1.0f); glRotatef(angle * 57.29578f, 0, 0, 1.0f);
glScalef(sx, sy, 1.0f); glScalef(sx, sy, 1.0f);
glTranslatef( ox, oy, 0); glTranslatef( ox, oy, 0);
+7 -7
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2009 LOVE Development Team * Copyright (c) 2006-2009 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -132,11 +132,11 @@ namespace opengl
FT_Done_Glyph(glyph); FT_Done_Glyph(glyph);
} }
TrueTypeFont::TrueTypeFont(Data * data, int size) TrueTypeFont::TrueTypeFont(Data * data, int size)
: Font(size), data(data), textures(0), list(0) : Font(size), data(data), textures(0), list(0)
{ {
data->retain(); data->retain();
} }
TrueTypeFont::~TrueTypeFont() TrueTypeFont::~TrueTypeFont()
{ {
@@ -159,7 +159,7 @@ namespace opengl
glPushMatrix(); glPushMatrix();
glTranslatef(ceil(x), ceil(y), 0.0f); glTranslatef(ceil(x), ceil(y), 0.0f);
glRotatef(angle, 0, 0, 1.0f); glRotatef(angle * 57.29578f, 0, 0, 1.0f);
glScalef(sx, sy, 1.0f); glScalef(sx, sy, 1.0f);
GLuint TrueTypeFont = list; GLuint TrueTypeFont = list;
@@ -197,7 +197,7 @@ namespace opengl
void TrueTypeFont::unload() void TrueTypeFont::unload()
{ {
unloadVolatile(); unloadVolatile();
} }
bool TrueTypeFont::loadVolatile() bool TrueTypeFont::loadVolatile()
{ {