guest42

Members
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

104 Neutral

About guest42

  • Rank
    Member
  1. Ah, thanks Matt, I appreciate the straight answer. I just wasn't sure how different Microsoft's C++ standards were from Gnu's, but I'll go on faith that it shouldn't be a big deal. Now to figure out how to set up OpenGL/Glut/Glui all over again.
  2. Yeah, I had installed VC just in case I got this answer. But what I'm not sure about is the fact that I've only ever used the gcc gnu compiler because I know my code will be generally cross platform. Will that change if I'm using Microsoft's IDE/compiler? That is to say, is their version of C++ different?
  3. Hey all. I've been using Dev CPP since I moved back to Windows when my Mac died. I like it because it's light weight, but I have a big problem. The debugger might as well not be there because I can't even watch variables. It's plain broken. I'm honestly fine with just printing variables to the console, but I'm using open GL, so I don't have a console (one of my big annoyances with Windows). So I'm wondering if there is some code I can use to enable a command line or if Dev CPP has some option that will give me a console window. Any help would be appreciated. thanks :)
  4. That did the trick! I actually had tried doing some sort of enabling during each draw cycle, but it may have been some different functions or just the wrong order. I still have things to learn about the OpenGL pipeline. Anyway, thank you very much :)
  5. Hey all, I'm trying to make my first CPP/OpenGL game, wherein the primary graphics are 2D vector-based polygons (so basically just using opengl's primitive drawing functions). However, I want some of the filled in shapes to have a measure of translucency, and so I want to use alpha blending. However, no code that I've used so far seems to do the trick, and I've tried all manner of functions, flags, and finagling to get it working. Basically this little bit of code is supposed to draw one circle half overlapping a second circle, but no matter what I set the alpha values to, and how I set my flags, the circles are always completely solid. Here is the main.cpp file: #include <gl/gl.h> #include <gl/glu.h> #include "glut.h" #include <vector> #include <math.h> #include <stdio.h> #include "EngineDrawGL.h" int w1; int h1; void orthogonalStart (void) { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, w1, 0, h1); glScalef(1, -1, 1); glTranslatef(0, -h1, 0); glMatrixMode(GL_MODELVIEW); } void orthogonalEnd (void) { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } void display (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor (0.0,0.0,0.0,1.0); glLoadIdentity(); orthogonalStart();; //drawshit glColor4f(1, 0, 0, .5); fill_circle_GL(100, 100, 30, 360); glColor4f(0, 0, 1, .5); fill_circle_GL(100, 120, 20, 360); orthogonalEnd(); glutSwapBuffers(); } void reshape (int w, int h) { glViewport (0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (60, (GLfloat)w / (GLfloat)h, 0.1, 1000.0); w1 = w; h1 = h; glMatrixMode (GL_MODELVIEW); glutPostRedisplay(); } void idle() { glutPostRedisplay(); } int main (int argc, char **argv) { //////set up window////////////// glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA); //glEnable(GL_DEPTH_TEST); //glEnable(GL_ALPHA_TEST); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glutInitWindowSize (800, 600); glutInitWindowPosition (100, 100); glutCreateWindow ("Model Part Editor"); glutIdleFunc( idle ); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutMainLoop (); return 0; } So basically, it sets up an openGL window, attempts to set up alpha blending, and then the draw function pops in and out of orthogonal mode, sandwhitching the circle drawing in between. There is also my circle drawing function which looks like this: void fill_circle_GL(float x1, float y1, float radius, int degrees) { glBegin(GL_POLYGON); int i; for (i=0; i < degrees; i++) { float degInRad = i*DEG2RAD; glVertex2f((cos(degInRad)*radius)+x1,(sin(degInRad)*radius)+y1); } glEnd(); } So I don't really know about the inner workings of OpenGL yet, but most of this code was stitched together from various examples. If anyone has any clue why the circles are still solid, please teach me :) Thanks for your time guest42
  6. Noob wants to render models

    Thanks for the reply! I actually am familiar with C++ and OOP, I really just am not a fan of the extended syntax of C++ over C. But anyway, I'm kind of wondering, is there any point to making one's own game engine when there are so many engines out there? Like, let's say I use crystal space or whatever... then to what extent will I actually be programming anything? To be honest, the thing that has made me hesitant about making games is that it seems like everything's already been done. Like, back in the day I really wanted to get into doing physics stuff related to game program, but with things like the Havok engine, is there a need for hardcore knowledge of physics in the game industry? I'm pretty naive on the subject, but I don't really want my game code to be just a framework of other people's libraries. Obviously openGL's capabilities are nice to have, along with it's tool kits. And I'll probably get a sound library because I'm not so interested in that. But if all the collision detection and physics and AI are done for me, it doesn't seem like much fun to get into.
  7. Noob wants to render models

    And that noob is me. After reluctantly switching from C to C++, I really want to start fiddling around with 3D stuff. I know some basic 3D math and linear algebra, but I'm still struggling on exactly how to start with openGL. Like, how does it all fit together in code? So I've been messing with blender, so I figure if I can make a simple model, and then write some code that renders it in openGL, that's a pretty good start. But I have a few questions that I'm sure the community has dealt with time and time again. First, what's a good format to export my models as that will be pretty simple to read into an object? I thought of doing md2, because I found a tutorial on using them in C++, but I can't get blender to export it properly. Maybe someone else has a better idea anyway? And then I guess I would probably need a tutorial on actually using that format in code form. So if anyone has any links or code or whatever for me, it would be much appreciated!
  8. Hey everyone. I made a little game in Java, complete with editors. Now I want to rewrite and improve the engine with C and OpenGL. I've done a lot of it, but I want to start building the editors and I need widgets: text boxes, buttons, etc. It has to follow a couple specifications. It needs to be in C, work cross platform (I am working on a Mac, my friend who may help me is working in Windows), and must be based off OpenGL or a common OpenGL toolkit (GLUT, SDL, etc). I thought it would be easy enough to find a library, but it seems like most of them are in C++, which is frustrating because I've managed to do the entire thing in C so far. I did find something called Open Tool Kit, which looks like what I need, but it doesn't compile in Mac because Mac doesn't have the glx.h header. So I'm looking for a solution. And I'd appreciate avoiding the obvious "Stop working with Mac" or "Use C++" unless there really is no other way. Thanks for your time and consideration.
  9. Per Pixel drawing

    That was it! Thank you so much. I'm going to be learning about 3D mathematics soon, and hopefully it will help me understand all this projection jazz so that I don't make mistakes like that.
  10. Per Pixel drawing

    Well, I am calling setup_opengl well after I initialize the graphics context. Here's the whole code: [CODE] #include <SDL/SDL.h> #include <OpenGL/gl.h> #include <stdio.h> #include <stdlib.h> SDL_Joystick *joystick; int width, height; double d(double f) { return f/800 * 1.0; } static void quit_tutorial( int code ) { SDL_JoystickClose(joystick); SDL_Quit( ); exit( code ); } static void handle_key_down( SDL_keysym* keysym ) { switch( keysym->sym ) { case SDLK_ESCAPE: quit_tutorial( 0 ); break; case SDLK_SPACE: break; default: break; } } static void process_events( void ) { SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: handle_key_down( &event.key.keysym ); break; case SDL_QUIT: /* Handle quit requests (like Ctrl-c). */ quit_tutorial( 0 ); break; case SDL_JOYAXISMOTION: if(event.jaxis.value < -3200) { if(event.jaxis.axis == 0) { printf("You hit the left button!\n"); } else if(event.jaxis.axis == 1) { printf("You hit the down button!\n"); } } else if(event.jaxis.value > 3200) { if(event.jaxis.axis == 0) { printf("You hit the right button!\n"); } else if(event.jaxis.axis == 1) { printf("You hit the up button!\n"); } } break; case SDL_JOYBUTTONDOWN: if ( event.jbutton.button == 0 ) { printf("You hit B!\n"); } else if ( event.jbutton.button == 1 ) { printf("You hit A!\n"); } else if ( event.jbutton.button == 2 ) { printf("You hit Select!\n"); } else if ( event.jbutton.button == 3 ) { printf("You hit Start!\n"); } break; } } } static void setup_opengl( int width, int height ) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } static void draw_screen( void ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable( GL_BLEND ); glColor4f(0.0, 1.0, 0.0, 1.0); //This works glBegin(GL_LINE_LOOP); glVertex2f( -1.0f, -1.0f); glVertex2f( -1.0f, 0.9f); glVertex2f( 0.9f, 0.9f); glVertex2f( 0.9f, -1.0f); glEnd(); //But I'd like to be able to draw within a larger projection glBegin(GL_LINE_LOOP); glVertex2f( 100, 100); glVertex2f( 100, 200); glVertex2f( 200, 200); glVertex2f( 200, 100); glEnd(); glPopMatrix(); SDL_GL_SwapBuffers( ); } int main( int argc, char* argv[] ) { /* Information about the current video settings. */ const SDL_VideoInfo* info = NULL; /* Color depth in bits of our window. */ int bpp = 0; /* Flags we will pass into SDL_SetVideoMode. */ int flags = 0; int error = SDL_Init(SDL_INIT_EVERYTHING); /* Let's get some video information. */ info = SDL_GetVideoInfo( ); if( !info ) { fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) ); quit_tutorial( 1 ); } /* * Set our width/height to 640/480 (you would * of course let the user decide this in a normal * app). We get the bpp we will request from * the display. On X11, VidMode can't change * resolution, so this is probably being overly * safe. Under Win32, ChangeDisplaySettings * can change the bpp. */ width = 800; height = 600; bpp = info->vfmt->BitsPerPixel; /* SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );*/ SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); /* * We want to request that SDL provide us * with an OpenGL window, in a fullscreen * video mode. */ flags = SDL_OPENGL | SDL_FULLSCREEN; if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); quit_tutorial( 1 ); } //Use Joystick SDL_JoystickEventState(SDL_ENABLE); joystick = SDL_JoystickOpen(0); setup_opengl( width, height ); //Main loop... process, draw while( 1 ) { process_events( ); draw_screen( ); } return 0; } [/CODE] Obviously it's mostly copy and pasted, but it seems like it should work. As I said, it achieves the desired effect when I'm using GLUT, but not SDL... I just don't know
  11. Per Pixel drawing

    Well, you're right that I shouldn't be using that gluOrth2D (I guess glOrtho is GL's equivalent?) I changed that, but it didn't fix my problem. However, using glvertex2i wouldn't make a difference. Perhaps I am making this sound more complicated than it needs to be? The site that I first learned openGL with GLUT is here: http://onesadcookie.com/Tutorials He describes the transformation like this: In OpenGL, you can use whatever coordinate system is useful to you. One of the most useful for 2D graphics is the projection where OpenGL units are precisely one pixel. That is the coordinate system that that same code used to let me use. If you take a look at that tutorial under Pixel-Perfect Projection, maybe you'll see what I mean.
  12. Per Pixel drawing

    Er, that's not quite what I meant. What I'm saying is, if my resolution is 800x600, I want 0,0 to be the lower left corner of the screen, and plotting a point at (800,600) would give me the upper right of the screen, and 400,300 would be the middle. Like working with Java's graphics (although with inversed Y plotting). Basically so I can plot in the range of 0x0 to 800x600 (Or whatever resolution I use) instead of -1 to 1.
  13. Per Pixel drawing

    I'm going to be making a 2D vector-graphics based game in C/OpenGL. I was using GLUT, but I decided to go with SDL as per advice in another thread because it supports USB joysticks. However, I want to be able to plot points on the screen per pixel (relative to the resolution rather than real pixels of course), with point 0, 0 being on the bottom left of the screen (therefor putting my entire view in the first quadrant). When I was using GLUT, I did this: [CODE]//Call this first, or every time window is resized static void setup_opengl( int width, int height ) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glMatrixMode(GL_MODELVIEW); } //Drawing function gets called every loop static void draw_screen( void ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable( GL_BLEND ); glColor4f(0.0, 1.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glVertex2f( 100, 100); glVertex2f( 100, 200); glVertex2f( 200, 200); glVertex2f( 200, 100); glEnd(); glPopMatrix(); //Swap buffers here }[/CODE] As you can see there aren't any actual glut calls here, so I figured it would work in SDL. However, when calling glVertex2f, it still wants a value between -1 and 1, with 0 being the center of the screen. Anyone know how I can change this? Oh, and on a side note, if anyone knows... I'm doing this with XCode in Mac OS X, but when I run my program, then exit and it comes back from fullscreen, and I can no longer minimize windows of applications that were running at the same time. I have to restart all my apps. It's pretty weird...
  14. Hi! I am currently programming a 2D game on Mac OS X using C/OpenGL with XCode. I have a simple USB controller (from retrozone) that I would like to be able to use in my game. How can I achieve this? Is there a library or interface I can use to make this possible? Later I would like to be able to port this game to Linux and Windows as well, so any information on those would also be helpful. Thanks :)
  15. Hi! I am new to OpenGL, and as of now I am starting to make a 2D top down game using vector graphics, using C.. I'm going to have grid lines running across the floor that that will scroll as the player moves to give the appearance that the player is moving (Kinda like Warning Forever, but you're not constantly moving). This was some java code that did the same thing that I will copy over once I've worked on some other things. 'view' is a rectangle object representing the area around the character in the center of the screen that the player can see. The grid will be 64x64 squares. The offsets are just for extra view offset from 'earthquake' effects and what have you: int vx = view.x%64; int vy = view.y%64; for(int i = 0; i <= view.width+64; i+=64) { g.drawLine((i-vx)-offsetX, 0, (i-vx)-offsetX, view.height); } for(int i = 0; i <= view.height+64; i+=64) { g.drawLine(0, (i-vy)-offsetY, view.width, (i-vy)-offsetY); } Okay, with that being said, these lines would be drawn all across the screen. What I want to do is have them only show inside of polygonal shapes, which will represent platforms the player can walk on, where as the rest of the screen represents 'void' and has no floor grid. In other words, if you have a sheet of grid paper and lay another black sheet of paper over that, you will only be able to see the grid paper where you've cut shapes out of the black paper. In Java I believe this was 'clipping', but I think that has another meaning in OpenGL. Anyway, does anyone know how I can achieve this effect? Is there some facility in OpenGL, or is there a pixel per pixel algorithm I have to use? Any help would be appreciated.