Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Xrid3r

  • Rank
  1. Xrid3r

    multiple objects - shots

    Oh, I see.. Thank you.. I know what to do now. ~Xrid3r.
  2. Xrid3r

    multiple objects - shots

    Quote:Make creation of the shot itself independent of rendering it. And can you please explain a little further, how I'm suppose to do that? ~Xrid3r
  3. Hi you guys! I've been working on a ripoff of the game Space invaders! I'm using CodeBlocks as IDE with openGL and glut. It has been working pretty well until now. The problem is laying in this function that handles the shots.. You see it's just spwning one shot. I want the program to spawn a shot every time you hit a button (I know how to do that part) and have the same x coordinate as the player position was when the shot was fired. Oh, I almost forgot.. I based the movment on the time elapsed since the program was started. Here is the code: void Shots(int shots) { shot s[shots]; const double t = glutGet(GLUT_ELAPSED_TIME) / 15000.0f; float t2 = t; for(int k = 0;k<=shots;k++) { s[k].y = t2-2.8f; s[k].x = p.x; glTranslatef(s[k].x,s[k].y,-6.0f); glPushMatrix(); //Draws the shot.. glPointSize(6.0f); glBegin(GL_POINTS); glVertex2f(0.0000000000005f,0.00000000000002f); glEnd(); glPopMatrix(); glLoadIdentity(); } } Hope you guys can help me out with this one. ~Xrid3r [Edited by - Xrid3r on December 28, 2010 12:35:32 PM]
  4. Hi you guys! I have been working with a little game in openGL for a while and things have worked out pretty well until now.. It's like the classic game spaceinvaders.. You see I'm using c++ and Codeblocks as IDE. and I've tried to make a spaceship that you can rotate and move in the rotated direction. I've also tried to make a weapon to the ship.. Hope someone of you can tell me about or give me somewhere i can read about the general structure of this two things. ~Xrid3r
  5. Xrid3r

    glut texture mapping problem

    I tried to remove the backface and cullface.. But it didn't made any differences.. Is there anything else that can be the reason to the images is not drawn? Or is it a bug in glut? Also.. I belive the Coords for the Quadrat should be: glTexCoord2f(1.0f,1.0f);glVertex3f(1.0f,1.0f,0.0f); glTexCoord2f(0.0f,1.0f);glVertex3f(-1.0f,1.0f,0.0f); glTexCoord2f(0.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f); glTexCoord2f(1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f); ~Xrid3r [Edited by - Xrid3r on September 23, 2010 8:36:18 AM]
  6. Xrid3r

    glut texture mapping problem

    Quote:Original post by Brother Bob Your frustum depth range is from Z=-2 to Z=-100, and you draw the quad at Z=0, so it's outside the view volume. Translate it, say, -5 units along the Z-axis to move it inside the view volume. Yes, but the image is still refusing be mapped.. Now it's just showing a white quadrat.. Can the problem be in the Loadtexture function or in the display function, were the scene is drawn? ~Xrid3r
  7. Hello! I've got a problem with my glut project.. You see.. I can compile without any warnings and errors.. It just showing a white window.. Instead of a mapped image.. Hope you can tell me whats wrong with it.. Here is the code: #include <windows.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif #include <gl/gl.h> #include <gl/glu.h> #include <stdlib.h> #include <stdio.h> GLuint LoadTexture(const char *filename,int width,int height,int wrap) { GLuint texture; unsigned char *data; FILE *file; file = fopen(filename,"r+"); if(file == NULL) { return 0; } data = (unsigned char*) malloc(width * height * 3); fread(data,width * height * 3,1,file); fclose(file); glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrap ? GL_REPEAT : GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrap ? GL_REPEAT : GL_CLAMP); gluBuild2DMipmaps(GL_TEXTURE_2D,3,width,height,GL_RGB,GL_UNSIGNED_BYTE,data); free(data); return texture; } static void resize(int width, int height) { const float ar = (float) width / (float) height; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity() ; } static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f); glTexCoord2f(1.0f,1.0f);glVertex3f(1.0f,1.0f,0.0f); glTexCoord2f(0.0f,1.0f);glVertex3f(-1.0f,1.0f,0.0f); glTexCoord2f(1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f); glEnd(); glutSwapBuffers(); } static void key(unsigned char key, int x, int y) { switch (key) { case 27 : case 'q': exit(0); break; } glutPostRedisplay(); } void init(void) { GLuint texture; glClearColor(0.0f,0.0f,0.0f,0.0f); glShadeModel(GL_SMOOTH); glEnable(GL_TEXTURE_2D); texture = LoadTexture("image.bmp",128,128,TRUE); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("GLUT Shapes"); glutReshapeFunc(resize); glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(display); init(); glClearColor(1,1,1,1); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glutMainLoop(); return EXIT_SUCCESS; } ~Xrid3r
  8. Xrid3r

    problem with glut font

    Quote:Original post by SiCrane Use "const char *" as a parameter instead of "char *". Yes, that removes the warning at least.. The problem now is that the font won't render.. Do you have any ideas why it won't render?
  9. Hi! I got a problem with my font-code in glut with codeblocks. I got this anoying warning that says "warning: deprecated conversion from string constant to 'char*" Here is the code: void renderBitmapString( float x, float y, void *font, char *string) { char *c; glRasterPos2f(x, y); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } } And the relevant information in the display function: renderBitmapString(5,30,GLUT_BITMAP_TIMES_ROMAN_24,"3D hello"); Hope you guys can tell me what's wrong and how i get rid of the warning message.. Oh and I got from Lighthouse. ~Xrid3r.
  10. Quote:Original post by Erik Rufelt You need to add a glBegin(GL_QUADS) after your call to glRotatef. You never tell OpenGL that you begin drawing, so the glVertex2d are ignored. Hehe, I saw it just before I read your last replay! Thanks man it all worked out now.. And thanks for the fast replay!
  11. Quote:Original post by Erik Rufelt Your data is RGB (3 bytes per pixel), but you tell OpenGL to use the data as GL_RGBA, which is 4 bytes per pixel. Try using GL_RGB. Thanks! that did work.. Now there's another problem.. You see.. Now I've got a black window that doesn't display my texture at all.. Any advice on this? Do I need to declare a normal for the surface? Edit: Yes, That's true.. But I still got this black window to deal with..
  12. Hi! Im trying to load a texture into an OpenGL scene.. The compiler doesn't give me any errors.. But when the program starts up I end up with windows error handler(Tells me to send a error report or ignore it).. However I use the default OpenGL code generated by CB.. Then I made some research about loading a texture into OpenGL without using SDL or something like that..I found this tutorial very helpful: http://www.nullterminator.net/gltexture.html . Hope you can give me some advice on how to fix this.. Here is my code: #include <windows.h> #include <gl/gl.h> #include <stdio.h> #include <stdlib.h> LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); void EnableOpenGL(HWND hwnd, HDC*, HGLRC*); void DisableOpenGL(HWND, HDC, HGLRC); GLuint LoadTextureBMP(const char * filename,int wrap) { GLuint texture; int width,height; BYTE * data; FILE * file; file = fopen(filename,"rb"); if(file == NULL) return 0; width = 256; height = 256; data = malloc(width * height * 3); fread(data,width*height*3,1,file); fclose(file); glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrap ? GL_REPEAT : GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrap ? GL_REPEAT : GL_CLAMP); glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,data); free(data); return texture; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; HWND hwnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; float theta = 0.0f; GLuint texture; /* register window class */ wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_OWNDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = "GLSample"; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);; if (!RegisterClassEx(&wcex)) return 0; /* create main window */ hwnd = CreateWindowEx(0, "GLSample", "OpenGL Sample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 256, 256, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); /* enable OpenGL for the window */ EnableOpenGL(hwnd, &hDC, &hRC); /* Enable Texture */ LoadTextureBMP("texture.bmp",TRUE); /* program main loop */ while (!bQuit) { /* check for messages */ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { /* handle or dispatch messages */ if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { /* OpenGL animation code goes here */ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture); glPushMatrix(); glRotatef(theta, 0.0f, 0.0f, 1.0f); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0); glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0); glEnd(); glPopMatrix(); glPopMatrix(); SwapBuffers(hDC); theta += 1.0f; Sleep (1); } } /* shutdown OpenGL */ DisableOpenGL(hwnd, hDC, hRC); /* destroy the window explicitly */ DestroyWindow(hwnd); return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: PostQuitMessage(0); break; case WM_DESTROY: return 0; case WM_KEYDOWN: { switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); break; } } break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC) { PIXELFORMATDESCRIPTOR pfd; int iFormat; /* get the device context (DC) */ *hDC = GetDC(hwnd); /* set the pixel format for the DC */ ZeroMemory(&pfd, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat(*hDC, &pfd); SetPixelFormat(*hDC, iFormat, &pfd); /* create and enable the render context (RC) */ *hRC = wglCreateContext(*hDC); wglMakeCurrent(*hDC, *hRC); } void DisableOpenGL (HWND hwnd, HDC hDC, HGLRC hRC) { wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(hwnd, hDC); } -Xrid3r Edit: Move this thread to the OpenGL topic..
  13. Xrid3r

    Problem with my openGL code

    @dmatter Hmm.. What is the afford of use the Visual 2010 c++ instead of use Code::Blocks? Anyway.. Thank you for the overview of the Win32/openGL.. The reason I was doing this was to understand exactly how you build a openGL code from scratch, you know.. Like if you want to invent the wheel all over again.. Is freeglut crossplatform like SFML seems to be? Secondly is C::B the best crossplatform compiler? ~Xrid3r
  14. Xrid3r

    Problem with my openGL code

    @Gage64 Yes that is true.. My mistake, I believe it should be: if(!(hWnd = CreateWindowEx(.. Now it entering my error handler which says "Can't create the window".. Any suggestion why it entering the error handler and refuses to display the window? @NumberXaero Would it be a good idea to assign PIXELFORMATDESCRIPTOR to "pdf" so you can assign the return value and check if it's NULL, like @Gage64 suggest? @PrestoChung Hmm.. What is the afford with SDL, if there are any? ~Xrid3r
  15. Xrid3r

    Problem with my openGL code

    @Gage64 Thanks for the information, but I prefer to use the old Dev-C++. Yes, it is based on the nehe code.. I trying to make my own version of it without the error handlers and fullscreen mode.. I also tried to move the last return statement outside the loop, but it still refuse to display my window. Any other suggestions? ~Xrid3r
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!