Skip to main content
gamedev.net
🔒 Locked

Begging for code!

Started by GDTheLaw Mar 26, 2009 at 7:48 PM 0 replies 550+ views
Original Post
GDTheLaw
GDTheLaw
I've got a quick question. I'm making a text mode simulation with SDL, and I wanted to convert my graphics OpenGL/SDL to see if there is any speed gains. I spent most of my day hacking up an init function and I have one working. All I need to do graphically with opengl is simple 2D vertical and horizontal lines (my text chars are mono color RLE compressed vertically or horizontally - whichever is best for each character), and bitmaps (I'd like to optionaly provide text chars as colored bitmaps). I don't really want to waste any more time or brain power on OpenGL, so I came here hoping to get a quick answer. Here's an init function that was borrowed and slightly modified from TheManaWorld source code... ------------------------------------------------------------------------- bool setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { // logger->log("Setting video mode %dx%d %s", // w, h, fs ? "fullscreen" : "windowed"); int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; ICDFullscreen = fs; ICDHWAccel = hwaccel; if (fs) { displayFlags |= SDL_FULLSCREEN; } //This causes a Segment Fault on my machine... //SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (!(ICDScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) { return false; } #ifdef __APPLE__ if (mSync) { const GLint VBL = 1; CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); } #endif // Setup OpenGL glViewport(0, 0, w, h); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); int gotDoubleBuffer; SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer); printf("Using OpenGL %s double buffering.", (gotDoubleBuffer ? "with" : "without")); char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS); GLint texSize; bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle"); if (rectTex) { //Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB; int TextureType = GL_TEXTURE_RECTANGLE_ARB; glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize); } else { //Image::mTextureType = GL_TEXTURE_2D; int TextureType = GL_TEXTURE_2D; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); } //Image::mTextureSize = texSize; int ICDTextureSize = texSize; printf("OpenGL texture size: %d pixels%s", ICDTextureSize, rectTex ? " (rectangle textures)" : ""); //Set caption SDL_WM_SetCaption( "OpenGL Test", NULL ); return true; } ------------------------------------------------------------------------------------- I'm asking OpenGl wiz's if this is the proper way to Init opengl. 'cause I've seen variations with other stuff inside like: -------------------------------------------------------------------------------- //Set projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 ); //Initialize modelview matrix glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); ------------------------------------------------------------------------------------ I haven't added this to my init yet, 'cause I don't understand it, so I don't know if I need it. Here's a drawline routine I found. I'd like to change it to separate, hopefully faster, horizontal and vertical versions. ----------------------------------------------------------------------------------- void drawLine(int x1, int y1, int x2, int y2) { setTexturingAndBlending(false); glBegin(GL_LINES); glVertex2f(x1 + 0.5f, y1 + 0.5f); glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); glBegin(GL_POINTS); glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); } ------------------------------------------------------------------------------------- Will this work well with my current hacked up Init. What I think I'm understanding is that OpenGL can use different perspectives, texture modes, and or coordinate systems of some kind. There seems to be different ways to Init it for 2D purposes. I just want it setup for max seed. I don't need blending or scaling, or anything else fancy, Just plain bitmaps and horizontal/vertical lines. Does anyone have a good clean Init(), DrawHorizontalLine(), DrawVerticalLine(), DrawSimpleBitmap() they could share or point me too? PS I've glanced over LazyFoo and NeHe tuts. They don't seem talk about 2D Lines, and I didn't find any good Bitmap blaster either. Also I'm working on 32 bit linux with GNU C++. Sorry I'm being lazy here and begging for some free code. But I've got a huge project that my mind is wrapped around right now, And I can't seem focus my attention on reading up an OpenGL. And given how little functionality I need from it right now, I'm ok with pasting in some code that I don't understand. Thanks for any and all help!
" In a world without fences and walls, who needs Gates and Windows?"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.