so I got this program...

Started by
11 comments, last by clint8565 19 years, 4 months ago
yeah I tried converting all the variables to floats because of the gl functions but it's stil messed so I changed them back and I got rid of all the f's and it's still messed

[Edited by - clint8565 on December 17, 2004 1:49:18 PM]
Advertisement
#ifndef __TEXTURE_H__#define __TEXTURE_H__#pragma comment(lib, "Opengl32.lib")					//Link to OpenGL32.lib so we can use OpenGL stuff#include <windows.h>									// Standard windows header#include <stdio.h>										// Standard I/O header #include <gl\gl.h>										// Header for OpenGL32 librarytypedef	struct									{	GLubyte	* imageData;									// Image Data (Up To 32 Bits)	GLuint	bpp;											// Image Color Depth In Bits Per Pixel	GLuint	width;											// Image Width	GLuint	height;											// Image Height	GLuint	texID;											// Texture ID Used To Select A Texture	GLuint	type;											// Image Type (GL_RGB, GL_RGBA)} Texture;	#endif
this is texture.h if that's what you want I don't have a texture.cpp (I didn't make this file)
//draw everythingvoid Render(NewEarth &Earth)//, NewTank &Player){  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);  glClear (GL_COLOR_BUFFER_BIT);  glColor3f(1.0f,1.0f,1.0f);    glEnable(GL_BLEND);  /*glBindTexture(GL_TEXTURE_2D, back[iback].texID);  glBegin(GL_QUADS);  glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);  glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 610.0f);  glTexCoord2f(1.0f, 1.0f); glVertex2f(800.0f, 610.0f);  glTexCoord2f(1.0f, 0.0f); glVertex2f(800.0f, 0.0f);  glEnd();    glBindTexture(GL_TEXTURE_2D,Player.tex.texID);  glBegin(GL_QUADS);  glTexCoord2f(Player.tloc[0],Player.tloc[1]);  glVertex2f(Player.Physics.loc[0],Player.Physics.loc[1]);  glTexCoord2f(Player.tloc[0],Player.tloc[3]);  glVertex2f(Player.Physics.loc[0]-(Player.Physics.uvec[1]*32.0),Player.Physics.loc[1]+(Player.Physics.uvec[0]*32.0));  glTexCoord2f(Player.tloc[2],Player.tloc[3]);  glVertex2f(Player.Physics.loc[2]-(Player.Physics.uvec[1]*32.0),Player.Physics.loc[3]+(Player.Physics.uvec[0]*32.0));  glTexCoord2f(Player.tloc[2],Player.tloc[1]);  glVertex2f(Player.Physics.loc[2],Player.Physics.loc[3]);  glEnd();    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  for(int a=0;a<16;a++)  {    if(Player.Pshot[a].active)    {      glBindTexture(GL_TEXTURE_2D, Player.Pshot[a].tex.texID);      glBegin(GL_QUADS);      glTexCoord2f(0.0f, 0.0f); glVertex2f(Player.Pshot[a].loc[0]-2.0, Player.Pshot[a].loc[1]-2.0);      glTexCoord2f(0.0f, 1.0f); glVertex2f(Player.Pshot[a].loc[0]-2.0, Player.Pshot[a].loc[1]+2.0);      glTexCoord2f(1.0f, 1.0f); glVertex2f(Player.Pshot[a].loc[0]+2.0, Player.Pshot[a].loc[1]+2.0);      glTexCoord2f(1.0f, 0.0f); glVertex2f(Player.Pshot[a].loc[0]+2.0, Player.Pshot[a].loc[1]-2.0);      glEnd();    }  }  for(int a=0;a<8;a++)  {    if(Player.Sshot[a].active)    {      glBindTexture(GL_TEXTURE_2D, Player.Sshot[a].tex.texID);      glBegin(GL_QUADS);      glTexCoord2f(0.0f, 0.0f); glVertex2f(Player.Sshot[a].loc[0]-4.0, Player.Sshot[a].loc[1]-4.0);      glTexCoord2f(0.0f, 1.0f); glVertex2f(Player.Sshot[a].loc[0]-4.0, Player.Sshot[a].loc[1]+4.0);      glTexCoord2f(1.0f, 1.0f); glVertex2f(Player.Sshot[a].loc[0]+4.0, Player.Sshot[a].loc[1]+4.0);      glTexCoord2f(1.0f, 0.0f); glVertex2f(Player.Sshot[a].loc[0]+4.0, Player.Sshot[a].loc[1]-4.0);      glEnd();    }  }*/    glBindTexture(GL_TEXTURE_2D, grass.texID);  glBegin(GL_LINES);  for(int a=0;a<800;a++)  {    glTexCoord2f(Earth.Dirt[a].loc[0]*0.00375,Earth.Dirt[a].loc[1]*0.00495);    glVertex2f(Earth.Dirt[a].loc[0],Earth.Dirt[a].loc[1]);    glTexCoord2f(Earth.Dirt[a].loc[2]*0.00375,Earth.Dirt[a].loc[3]*0.00495);    glVertex2f(Earth.Dirt[a].loc[2],Earth.Dirt[a].loc[3]);  }  glEnd();      /*glBegin(GL_QUADS);  for(int a=0;a<128;a++)  {    if(Earth.Chunk[a].active)    {      glTexCoord2f(0.0f,0.0f);      glVertex2f(Earth.Chunk[a].loc[0]-1.5,Earth.Chunk[a].loc[1]-1.5);      glTexCoord2f(0.0f,0.1f);      glVertex2f(Earth.Chunk[a].loc[0]-1.5,Earth.Chunk[a].loc[1]+1.5);      glTexCoord2f(0.1f,0.1f);      glVertex2f(Earth.Chunk[a].loc[0]+1.5,Earth.Chunk[a].loc[1]+1.5);      glTexCoord2f(0.1f,0.0f);      glVertex2f(Earth.Chunk[a].loc[0]+1.5,Earth.Chunk[a].loc[1]-1.5);    }    }  glEnd();    glDisable(GL_BLEND);  glBegin(GL_LINES);  for(int a=0;a<=Player.pwait;a++)  {    glColor3f(1.0f,0.0f,0.0f);    glVertex2f(50.0+(a*2.0),550.0f);    glVertex2f(50.0+(a*2.0),540.0f);  }  glEnd();  glBegin(GL_LINES);  for(int a=0;a<=Player.swait;a+=10)  {    glColor3f(0.0f,0.0f,1.0f);    glVertex2f(50.0+(a/5.0),535.0f);    glVertex2f(50.0+(a/5.0),525.0f);  }  glEnd();  glBegin(GL_LINES);  for(int a=0;a<=Player.jet;a+=2)  {    glColor3f(0.0f,1.0f,0.0f);    glVertex2f(50.0+a,520.0f);    glVertex2f(50.0+a,510.0f);  }    glEnd();*/    glFlush();}/************************** * WinMain * **************************/int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow){  WNDCLASS wc;  HWND hWnd;  HDC hDC;  HGLRC hRC;          MSG msg;  BOOL bQuit = FALSE;  DWORD t, ct;  /* register window class */  wc.style = CS_OWNDC;  wc.lpfnWndProc = WndProc;  wc.cbClsExtra = 0;  wc.cbWndExtra = 0;  wc.hInstance = hInstance;  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);  wc.hCursor = LoadCursor (NULL, IDC_ARROW);  wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);  wc.lpszMenuName = NULL;  wc.lpszClassName = "GLTest";  RegisterClass (&wc);  /* create main window */  hWnd = CreateWindow ("GLTest", "OpenGL Test", WS_BORDER | WS_POPUPWINDOW | WS_VISIBLE,                        0, 0, 800, 600, NULL, NULL, hInstance, NULL);  /* enable OpenGL for the window */  EnableOpenGL (hWnd, &hDC, &hRC);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  glMatrixMode(GL_MODELVIEW);  glDisable(GL_DEPTH_TEST);  glEnable(GL_TEXTURE_2D);  glTranslatef(-1.0f,-1.0f,0.0f);  glScalef(0.0025f,0.0033f,0.0f);    timeBeginPeriod(1);  //seed random # generator  srand(static_cast<unsigned>(time(0)));  iback=rand()%5;    //textures  if(!LoadGLTextures())    bQuit=true;    //init dirt  NewEarth Earth;  for(int a=0;a<800;a++)  {    Earth.Dirt[a].strength=(rand()%4);    Earth.Dirt[a].loc[0]=a;    Earth.Dirt[a].loc[1]=0.0;    Earth.Dirt[a].loc[2]=a;    Earth.Dirt[a].loc[3]=(rand()%320)+50;  }  for(int a=0;a<128;a++)  {    //ResetChunk(Earth.Chunk[a]);  }      //init Tank  //NewTank Player;  //InitTank(Player);  //Player.tex=tank[1];  //for(int a=0;a<16;a++)  //  Player.Pshot[a].tex=tex[0];  //for(int a=0;a<8;a++)  //  Player.Sshot[a].tex=tex[1];    /* program main loop */  while (!bQuit)  {    t=timeGetTime(); //get time in milliseconds    /* 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    {      Sleep(1);      //check for landslide      //Landslide(Earth);            //do stuff...      ct=timeGetTime();      //if(Player.jet<100)      //  Player.jet+=ct-t;      //Hover(Player,Earth,ct,t);        //Controls(Player,bQuit,t,ct);      //Move(Player,Earth,t,ct);            //draw everything      Render(Earth);//,Player);            SwapBuffers (hDC);    }  }    timeEndPeriod(1);  /* shutdown OpenGL */  DisableOpenGL (hWnd, hDC, hRC);  /* destroy the window explicitly */  DestroyWindow (hWnd);  return msg.wParam;}
good ^^^^
there it works like this with everything, but the terrain commented
as soon as I iclude the player in the render function it screws up because I have to uncomment InitTank, but I don't see how that affects the terrain because the terrain doesn't even get passed to InitTank
//draw everythingvoid Render(NewEarth &Earth, NewTank &Player){  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);  glClear (GL_COLOR_BUFFER_BIT);  glColor3f(1.0f,1.0f,1.0f);    glEnable(GL_BLEND);  /*glBindTexture(GL_TEXTURE_2D, back[iback].texID);  glBegin(GL_QUADS);  glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);  glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 610.0f);  glTexCoord2f(1.0f, 1.0f); glVertex2f(800.0f, 610.0f);  glTexCoord2f(1.0f, 0.0f); glVertex2f(800.0f, 0.0f);  glEnd();    glBindTexture(GL_TEXTURE_2D,Player.tex.texID);  glBegin(GL_QUADS);  glTexCoord2f(Player.tloc[0],Player.tloc[1]);  glVertex2f(Player.Physics.loc[0],Player.Physics.loc[1]);  glTexCoord2f(Player.tloc[0],Player.tloc[3]);  glVertex2f(Player.Physics.loc[0]-(Player.Physics.uvec[1]*32.0),Player.Physics.loc[1]+(Player.Physics.uvec[0]*32.0));  glTexCoord2f(Player.tloc[2],Player.tloc[3]);  glVertex2f(Player.Physics.loc[2]-(Player.Physics.uvec[1]*32.0),Player.Physics.loc[3]+(Player.Physics.uvec[0]*32.0));  glTexCoord2f(Player.tloc[2],Player.tloc[1]);  glVertex2f(Player.Physics.loc[2],Player.Physics.loc[3]);  glEnd();    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  for(int a=0;a<16;a++)  {    if(Player.Pshot[a].active)    {      glBindTexture(GL_TEXTURE_2D, Player.Pshot[a].tex.texID);      glBegin(GL_QUADS);      glTexCoord2f(0.0f, 0.0f); glVertex2f(Player.Pshot[a].loc[0]-2.0, Player.Pshot[a].loc[1]-2.0);      glTexCoord2f(0.0f, 1.0f); glVertex2f(Player.Pshot[a].loc[0]-2.0, Player.Pshot[a].loc[1]+2.0);      glTexCoord2f(1.0f, 1.0f); glVertex2f(Player.Pshot[a].loc[0]+2.0, Player.Pshot[a].loc[1]+2.0);      glTexCoord2f(1.0f, 0.0f); glVertex2f(Player.Pshot[a].loc[0]+2.0, Player.Pshot[a].loc[1]-2.0);      glEnd();    }  }  for(int a=0;a<8;a++)  {    if(Player.Sshot[a].active)    {      glBindTexture(GL_TEXTURE_2D, Player.Sshot[a].tex.texID);      glBegin(GL_QUADS);      glTexCoord2f(0.0f, 0.0f); glVertex2f(Player.Sshot[a].loc[0]-4.0, Player.Sshot[a].loc[1]-4.0);      glTexCoord2f(0.0f, 1.0f); glVertex2f(Player.Sshot[a].loc[0]-4.0, Player.Sshot[a].loc[1]+4.0);      glTexCoord2f(1.0f, 1.0f); glVertex2f(Player.Sshot[a].loc[0]+4.0, Player.Sshot[a].loc[1]+4.0);      glTexCoord2f(1.0f, 0.0f); glVertex2f(Player.Sshot[a].loc[0]+4.0, Player.Sshot[a].loc[1]-4.0);      glEnd();    }  }*/    glBindTexture(GL_TEXTURE_2D, grass.texID);  glBegin(GL_LINES);  for(int a=0;a<800;a++)  {    glTexCoord2f(Earth.Dirt[a].loc[0]*0.00375,Earth.Dirt[a].loc[1]*0.00495);    glVertex2f(Earth.Dirt[a].loc[0],Earth.Dirt[a].loc[1]);    glTexCoord2f(Earth.Dirt[a].loc[2]*0.00375,Earth.Dirt[a].loc[3]*0.00495);    glVertex2f(Earth.Dirt[a].loc[2],Earth.Dirt[a].loc[3]);  }  glEnd();      /*glBegin(GL_QUADS);  for(int a=0;a<128;a++)  {    if(Earth.Chunk[a].active)    {      glTexCoord2f(0.0f,0.0f);      glVertex2f(Earth.Chunk[a].loc[0]-1.5,Earth.Chunk[a].loc[1]-1.5);      glTexCoord2f(0.0f,0.1f);      glVertex2f(Earth.Chunk[a].loc[0]-1.5,Earth.Chunk[a].loc[1]+1.5);      glTexCoord2f(0.1f,0.1f);      glVertex2f(Earth.Chunk[a].loc[0]+1.5,Earth.Chunk[a].loc[1]+1.5);      glTexCoord2f(0.1f,0.0f);      glVertex2f(Earth.Chunk[a].loc[0]+1.5,Earth.Chunk[a].loc[1]-1.5);    }    }  glEnd();    glDisable(GL_BLEND);  glBegin(GL_LINES);  for(int a=0;a<=Player.pwait;a++)  {    glColor3f(1.0f,0.0f,0.0f);    glVertex2f(50.0+(a*2.0),550.0f);    glVertex2f(50.0+(a*2.0),540.0f);  }  glEnd();  glBegin(GL_LINES);  for(int a=0;a<=Player.swait;a+=10)  {    glColor3f(0.0f,0.0f,1.0f);    glVertex2f(50.0+(a/5.0),535.0f);    glVertex2f(50.0+(a/5.0),525.0f);  }  glEnd();  glBegin(GL_LINES);  for(int a=0;a<=Player.jet;a+=2)  {    glColor3f(0.0f,1.0f,0.0f);    glVertex2f(50.0+a,520.0f);    glVertex2f(50.0+a,510.0f);  }    glEnd();*/    glFlush();}/************************** * WinMain * **************************/int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow){  WNDCLASS wc;  HWND hWnd;  HDC hDC;  HGLRC hRC;          MSG msg;  BOOL bQuit = FALSE;  DWORD t, ct;  /* register window class */  wc.style = CS_OWNDC;  wc.lpfnWndProc = WndProc;  wc.cbClsExtra = 0;  wc.cbWndExtra = 0;  wc.hInstance = hInstance;  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);  wc.hCursor = LoadCursor (NULL, IDC_ARROW);  wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);  wc.lpszMenuName = NULL;  wc.lpszClassName = "GLTest";  RegisterClass (&wc);  /* create main window */  hWnd = CreateWindow ("GLTest", "OpenGL Test", WS_BORDER | WS_POPUPWINDOW | WS_VISIBLE,                        0, 0, 800, 600, NULL, NULL, hInstance, NULL);  /* enable OpenGL for the window */  EnableOpenGL (hWnd, &hDC, &hRC);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  glMatrixMode(GL_MODELVIEW);  glDisable(GL_DEPTH_TEST);  glEnable(GL_TEXTURE_2D);  glTranslatef(-1.0f,-1.0f,0.0f);  glScalef(0.0025f,0.0033f,0.0f);    timeBeginPeriod(1);  //seed random # generator  srand(static_cast<unsigned>(time(0)));  iback=rand()%5;    //textures  if(!LoadGLTextures())    bQuit=true;    //init dirt  NewEarth Earth;  for(int a=0;a<800;a++)  {    Earth.Dirt[a].strength=(rand()%4);    Earth.Dirt[a].loc[0]=a;    Earth.Dirt[a].loc[1]=0.0;    Earth.Dirt[a].loc[2]=a;    Earth.Dirt[a].loc[3]=(rand()%320)+50;  }  for(int a=0;a<128;a++)  {    //ResetChunk(Earth.Chunk[a]);  }      //init Tank  NewTank Player;  InitTank(Player);  Player.tex=tank[1];  for(int a=0;a<16;a++)    Player.Pshot[a].tex=tex[0];  for(int a=0;a<8;a++)    Player.Sshot[a].tex=tex[1];    /* program main loop */  while (!bQuit)  {    t=timeGetTime(); //get time in milliseconds    /* 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    {      Sleep(1);      //check for landslide      //Landslide(Earth);            //do stuff...      ct=timeGetTime();      //if(Player.jet<100)      //  Player.jet+=ct-t;      //Hover(Player,Earth,ct,t);        //Controls(Player,bQuit,t,ct);      //Move(Player,Earth,t,ct);            //draw everything      Render(Earth,Player);            SwapBuffers (hDC);    }  }    timeEndPeriod(1);  /* shutdown OpenGL */  DisableOpenGL (hWnd, hDC, hRC);  /* destroy the window explicitly */  DestroyWindow (hWnd);  return msg.wParam;}
bad ^^^^

This topic is closed to new replies.

Advertisement