AllegroGL error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 7
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

AllegroGL error

 
0
  #1
Aug 1st, 2009
Every time I try to execute my program I get an error:"The instruction at "0x00401585" refereced memory at "0x00000028".The memory could not be "read"". Pleas help me!

I have linked -lagl -lalleg -luser32 -lgdi32 -lopengl32 -lglu32
I can't see the problem.


  1. #include <gl\gl.h>
  2. #include <GL\glu.h>
  3.  
  4. #include <allegro.h>
  5. #include <alleggl.h>
  6.  
  7. int timer;
  8.  
  9. void update_timer() {
  10. timer++;
  11. }
  12. END_OF_FUNCTION(update_timer);
  13. bool light=true, fog=true;
  14.  
  15. void initGL(bool FULLSCREEN,int h,int w); // initializate openGL
  16. void correctPerspective(GLfloat z1,GLfloat z2); // correct the perspective
  17.  
  18. void DrawScene(GLfloat X,GLfloat Y,GLfloat Z,GLfloat dist);
  19. BITMAP* tex;
  20.  
  21. GLuint filter; // Which Filter To Use
  22. GLuint texture[3];
  23.  
  24. const GLfloat ACC=0.003f;
  25. const GLfloat DACC=0.002f;
  26.  
  27. void initRendering(); // in this function we enabble GL modules
  28.  
  29. int main() {
  30. float d = - 4,rtriX=0,rtriY=0,rtriZ=0,AX=0,AY=0,AZ=0;
  31.  
  32. /* Initialize both Allegro and AllegroGL */
  33. allegro_init();
  34. initGL(true,1366,768);
  35. install_keyboard();
  36. install_timer();
  37. LOCK_VARIABLE(timer);
  38. LOCK_FUNCTION(update_timer);
  39. install_int_ex(update_timer, BPS_TO_TIMER(30));
  40. tex=load_bitmap("Crate.bmp",NULL);
  41. GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
  42. GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
  43. GLfloat LightPosition[]= { 1.0f, 1.0f, 1.0f, 1.0f };
  44. float fogColor[4]={0.3,0.3,0.3,0.6};
  45.  
  46. glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
  47. glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
  48. glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
  49. glEnable(GL_LIGHT1);
  50.  
  51. //==============================================
  52. glFogfv(GL_FOG_COLOR, fogColor);
  53. glHint(GL_FOG_HINT, GL_NICEST);
  54. glFogi(GL_FOG_MODE, GL_LINEAR);
  55. glFogf(GL_FOG_DENSITY, 0.1);
  56. glFogf(GL_FOG_START, 1.0);
  57. glFogf(GL_FOG_END, 8.0);
  58. //=================================================
  59.  
  60. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth
  61.  
  62. initRendering();
  63. /* Correct the perspective */
  64. correctPerspective(1.5f, 60.0f);
  65. glTexEnvi(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE, GL_DECAL);
  66. //============================
  67. glGenTextures(3, &texture[0]); // Create Three Textures
  68.  
  69. // Create Nearest Filtered Texture
  70. glBindTexture(GL_TEXTURE_2D, texture[0]);
  71. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  72. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  73. glTexImage2D(GL_TEXTURE_2D, 0, 3, tex[0].w, tex[0].h, 0, GL_RGB, GL_UNSIGNED_BYTE, tex[0].dat);
  74.  
  75. // Create Linear Filtered Texture
  76. glBindTexture(GL_TEXTURE_2D, texture[1]);
  77. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  78. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  79. glTexImage2D(GL_TEXTURE_2D, 0, 3, tex[0].w, tex[0].h, 0, GL_RGB, GL_UNSIGNED_BYTE, tex[0].dat);
  80.  
  81. // Create MipMapped Texture
  82. glBindTexture(GL_TEXTURE_2D, texture[2]);
  83. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  84. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
  85. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, tex[0].w, tex[0].h, GL_RGB, GL_UNSIGNED_BYTE, tex[0].dat);
  86. //============================
  87. while(!key[KEY_ESC]) {
  88. while( timer >0 ) {
  89. if( key[KEY_UP] )
  90. rtriX-=ACC;
  91. if( key[KEY_DOWN] )
  92. rtriX+=ACC;
  93. else if(!key[KEY_UP] && !key[KEY_DOWN] && rtriX !=0) {
  94. if( rtriX > 0 )
  95. rtriX-=DACC;
  96. if( rtriX < 0 )
  97. rtriX+=DACC;
  98. }
  99. if( key[KEY_RIGHT] )
  100. rtriY+=ACC;
  101. if( key[KEY_LEFT] )
  102. rtriY-=ACC;
  103. else if(!key[KEY_LEFT] && !key[KEY_RIGHT] && rtriY !=0) {
  104. if( rtriY > 0 )
  105. rtriY-=DACC;
  106. if( rtriY < 0 )
  107. rtriY+=DACC;
  108. }
  109. if( key[KEY_A] )
  110. rtriZ-=ACC;
  111. if( key[KEY_D] )
  112. rtriZ+=ACC;
  113. if( !key[KEY_A] && !key[KEY_D] && rtriZ !=0) {
  114. if( rtriZ > 0 )
  115. rtriZ-=DACC;
  116. if( rtriZ < 0 )
  117. rtriZ+=DACC;
  118. }
  119. if(key[KEY_Z])
  120. d+=0.1f;
  121. if(key[KEY_X])
  122. d-=0.1f;
  123. if(key[KEY_I]&&key[KEY_L])
  124. light=true;
  125. if(key[KEY_O]&&key[KEY_L])
  126. light=false;
  127. if(key[KEY_I]&&key[KEY_F])
  128. fog=true;
  129. if(key[KEY_O]&&key[KEY_F])
  130. fog=false;
  131. if(key[KEY_T]&&key[KEY_1])
  132. filter=0;
  133. if(key[KEY_T]&&key[KEY_2])
  134. filter=1;
  135. if(key[KEY_T]&&key[KEY_3])
  136. filter=2;
  137. timer--;
  138. }
  139. AX=(AX+rtriX);
  140. AY=(AY+rtriY);
  141. AZ=(AZ+rtriZ);
  142. DrawScene(AX,AY,AZ,d);
  143.  
  144. }
  145. /* Wait for the user to press a key */
  146. readkey();
  147.  
  148. /* Finished. */
  149. return 0;
  150. }
  151. END_OF_MAIN();
  152.  
  153. void initRendering() {
  154. glEnable(GL_DEPTH_TEST);
  155. glEnable(GL_LEQUAL);
  156. glEnable(GL_TEXTURE_2D);
  157. glEnable(GL_BLEND);
  158. glEnable(GL_FOG);
  159. glEnable(GL_LIGHTING);
  160. glEnable(GL_POLYGON_SMOOTH);
  161. glEnable(GL_LINE_SMOOTH);
  162. // more modules...
  163. }
  164.  
  165. void initGL(bool FULLSCREEN,int w,int h) {
  166. install_allegro_gl();
  167. allegro_gl_set( AGL_COLOR_DEPTH, 32 );
  168. allegro_gl_set( AGL_Z_DEPTH, 8 );
  169. allegro_gl_set( AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH );
  170. if(FULLSCREEN)
  171. if(set_gfx_mode( GFX_OPENGL_FULLSCREEN, w, h, 0, 0 )) {
  172. allegro_message( "There was an error creating the window" );
  173. }
  174. if(!FULLSCREEN)
  175. if(set_gfx_mode( GFX_OPENGL_WINDOWED, w, h, 0, 0 )) {
  176. allegro_message( "There was an error creating the window" );
  177. }
  178.  
  179. }
  180.  
  181. void correctPerspective(GLfloat z1,GLfloat z2) {
  182. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  183. glMatrixMode(GL_PROJECTION);
  184. glLoadIdentity();
  185. glMatrixMode(GL_MODELVIEW);
  186. glLoadIdentity();
  187. float fMinX = -1.0f, fMaxX = 1.0f,
  188. fMinY = -1.0f, fMaxY = 1.0f;
  189. float fAspectRatio = SCREEN_W / (float)SCREEN_H;
  190. if ( fAspectRatio > 1.0f ) {
  191. fMinY = fMinX / fAspectRatio;
  192. fMaxY = fMaxX / fAspectRatio;
  193. }
  194. else {
  195. fMinX = fMinY * fAspectRatio;
  196. fMaxX = fMaxY * fAspectRatio;
  197. }
  198. glFrustum( fMinX, fMaxX, fMinY, fMaxY, z1, z2 );
  199. }
  200.  
  201.  
  202.  
  203. void DrawScene(GLfloat X,GLfloat Y,GLfloat Z,GLfloat dist) {
  204. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  205. if( light==true )
  206. glEnable(GL_LIGHT1);
  207. if( light==false)
  208. glDisable(GL_LIGHT1);
  209. if( fog==true )
  210. glEnable(GL_FOG);
  211. if( fog==false)
  212. glDisable(GL_FOG);
  213. glPushMatrix();
  214. glTranslatef(0.0f,0.0f,dist);
  215. glBindTexture(GL_TEXTURE_2D, texture[filter]);
  216. glRotatef(X,1.0f,0.0f,0.0f);
  217. glRotatef(Y,0.0f,1.0f,0.0f);
  218. glRotatef(Z,0.0f,0.0f,1.0f);
  219. glBegin(GL_QUADS);
  220. glColor4f(1.0f,0.0f,0.0f,0.5f);
  221. glNormal3f( 0.0f, 0.0f, -1.0f);
  222. glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
  223. glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
  224. glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
  225. glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
  226. // Back Face
  227. glNormal3f( 0.0f, 0.0f,1.0f);
  228. glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
  229. glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
  230. glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
  231. glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
  232. // Top Face
  233. glNormal3f( 0.0f, -1.0f, 0.0f);
  234. glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
  235. glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
  236. glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
  237. glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
  238. // Bottom Face
  239. glNormal3f( 0.0f,1.0f, 0.0f);
  240. glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
  241. glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
  242. glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
  243. glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
  244. // Right face
  245. glNormal3f( -1.0f, 0.0f, 0.0f);
  246. glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
  247. glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
  248. glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
  249. glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
  250. // Left Face
  251. glNormal3f(1.0f, 0.0f, 0.0f);
  252. glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
  253. glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
  254. glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
  255. glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
  256. glEnd();
  257. glPopMatrix();
  258. glPushMatrix();
  259. glTranslatef(0.0f,0.0f,-20.0f);
  260. glBegin(GL_QUADS);
  261. glColor3f(0.0f,0.0f,0.0f);
  262. glVertex2f(-15.0f,10.0f);
  263. glVertex2f(15.0f,10.0f);
  264. glVertex2f(15.0f,-10.0f);
  265. glVertex2f(-15.0f,-10.0f);
  266. glEnd();
  267. glPopMatrix();
  268. allegro_gl_flip();
  269. }

Last edited by Nickyu0712; Aug 1st, 2009 at 6:42 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC