Jump to content

  • Log In with Google      Sign In   
  • Create Account

can anyone figure out why this wont work ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 04:22 PM

im trying to get use to using opengl with sdl and when i try to bind a texture and apply it to a GL_QUAD it wont work ?

im going attach a zip with the contents of the application below (IDE is CodeBlocks)

 

Image of screen 

21z9ts.png

 

if anyone could help it would mean a lot! Thank you for your time

Attached Files


Edited by MrPhoenix, 18 January 2013 - 05:28 PM.


Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 4330

Like
0Likes
Like

Posted 18 January 2013 - 04:39 PM

You need to declare global variables with external linkage, otherwise, each c file will have its own copy of those variables. Calling graphics_engine_init will modify graphics.c's version of screen and menu_image. See problem #4 in Organizing Code Files in C and C++.

Edited by fastcall22, 18 January 2013 - 04:40 PM.

c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#3 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 04:42 PM

thanks fastcall22 im going work on this, ill let you know if i get it to work or not



#4 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 05:29 PM

Fastcall22 i did what it said and it still just a black screen ?

 

i reuploaded a new copy of the code with a compiled version in the bin/debug folder



#5 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 05:39 PM

i converted all the code to a single file

 

http://pastie.org/5722381

 

and still the same result ?????????



#6 swiftcoder   Senior Moderators   -  Reputation: 9990

Like
1Likes
Like

Posted 18 January 2013 - 05:46 PM

You are rendering your quad along the wrong axis. The camera (screen) faces along the Z-axis - you are treating it as facing along the Y-axis.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#7 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 05:50 PM

swiftcoder should i use glTranslatef() or go and change the glVertex3f() in the quads ?



#8 fastcall22   Crossbones+   -  Reputation: 4330

Like
1Likes
Like

Posted 18 January 2013 - 05:51 PM


#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <GL/gl.h>
#include <GL/glu.h>

#ifndef GRAP_HEADER_H
#define GRAP_HEADER_H
    SDL_Surface *screen;
    GLuint menu_image;
#endif

void graphics_engine_init();
void graphics_engine_exit();
GLuint LoadTexture(char *filename,int textw,int texth);
void DrawTexture(int x, int y, int textw,int texth, GLuint textureid);


No, not quite. (You're looking at "Fixing problem #3". (I think.))

Quickfix:
// graphics.h
extern SDL_Surface *screen;
extern GLuint menu_image;

// graphics.cpp
SDL_Surface *screen;
GLuint menu_image;

When a source file encounters an "extern", it is told that this variable exists, but resides elsewhere. Without the extern, each source file refers to its own version of those variables. When your program is linked, all of the externed variables are hooked up to the (one and only) location.

(Quite a shoddy explanation, but I hope it helps.)

Edited by fastcall22, 18 January 2013 - 05:51 PM.

c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#9 swiftcoder   Senior Moderators   -  Reputation: 9990

Like
1Likes
Like

Posted 18 January 2013 - 06:03 PM

swiftcoder should i use glTranslatef() or go and change the glVertex3f() in the quads?

I'd switch it right in the vertex calls, at least for now. Better to get it working before adding further complexity.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#10 MrPhoenix   Members   -  Reputation: 134

Like
0Likes
Like

Posted 18 January 2013 - 06:16 PM

Ok i fixed the quad and the view but the the quad wont accept the texture ???/

it just a plain quad ?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS