Jump to content
  • Advertisement
Sign in to follow this  
Randall Perkins

OpenGL can anyone figure out why this wont work ?

This topic is 2151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Edited by MrPhoenix

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

[quote name='MrPhoenix' timestamp='1358553041' post='5023030']
swiftcoder should i use glTranslatef() or go and change the glVertex3f() in the quads?[/quote]

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!